Use the send method to call every endpoint except for oauth/tokens
public static send ( |
||
$client | ||
$endPoint | string | E.g. "/tickets.json" |
$options | array | Available options are listed below: array $queryParams Array of unencoded key-value pairs, e.g. ["ids" => "1,2,3,4"] array $postFields Array of unencoded key-value pairs, e.g. ["filename" => "blah.png"] string $method "GET", "POST", etc. Default is GET. string $contentType Default is "application/json" |
Результат | stdClass | | null The response body, parsed from JSON into an object. Also returns null if something went wrong |
/** * Recovering suspended tickets. * * @param array $ids * * @return mixed * @throws MissingParametersException * @throws \Zendesk\API\Exceptions\ApiResponseException * @throws \Zendesk\API\Exceptions\RouteException * */ public function recoverMany(array $ids) { if (!is_array($ids)) { throw new MissingParametersException(__METHOD__, ['ids']); } $response = Http::send($this->client, $this->getRoute(__FUNCTION__), ['method' => 'PUT', 'queryParams' => ['ids' => implode(',', $ids)]]); return $response; }
/** * Show multiple resources * * @param array $ids Array of IDs to delete * @param string $key Could be `id` or `external_id` * * @return mixed * */ public function deleteMany(array $ids = [], $key = 'ids') { try { $route = $this->getRoute(__FUNCTION__); } catch (RouteException $e) { if (!isset($this->resourceName)) { $this->resourceName = $this->getResourceNameFromClass(); } $route = $this->resourceName . '/destroy_many.json'; $this->setRoute('', $route); } $response = Http::send($this->client, $route, ['method' => 'DELETE', 'queryParams' => [$key => implode(',', $ids)]]); $this->client->setSideload(null); return $response; }
/** * Uploads an file with the given upload name. * * @param array $params * * @param string $routeKey * @return null|\stdClass * @throws CustomException * @throws MissingParametersException */ public function upload(array $params, $routeKey = __FUNCTION__) { if (!array_key_exists('file', $params)) { throw new MissingParametersException(__METHOD__, ['file']); } if (!file_exists($params['file'])) { throw new CustomException('File ' . $params['file'] . ' could not be found in ' . __METHOD__); } try { $route = $this->getRoute($routeKey, $params); } catch (RouteException $e) { if (!isset($this->resourceName)) { $this->resourceName = $this->getResourceNameFromClass(); } $this->setRoute(__FUNCTION__, $this->resourceName . '/uploads.json'); $route = $this->resourceName . '/uploads.json'; } $response = Http::send($this->client, $route, ['method' => $this->getUploadRequestMethod(), 'multipart' => [['name' => $this->getUploadName(), 'contents' => new LazyOpenStream($params['file'], 'r'), 'filename' => $params['file']]]]); return $response; }
/** * Update group of resources * * @param array $params * @param string $key Could be `id` or `external_id` * * @return \stdClass | null */ public function updateMany(array $params, $key = 'ids') { try { $route = $this->getRoute(__FUNCTION__); } catch (RouteException $e) { if (!isset($this->resourceName)) { $this->resourceName = $this->getResourceNameFromClass(); } $route = $this->resourceName . '/update_many.json'; $this->setRoute('updateMany', $route); } $resourceUpdateName = $this->objectNamePlural; $queryParams = []; if (isset($params[$key]) && is_array($params[$key])) { $queryParams[$key] = implode(',', $params[$key]); unset($params[$key]); $resourceUpdateName = $this->objectName; } $response = Http::send($this->client, $route, ['queryParams' => $queryParams, 'postFields' => [$resourceUpdateName => $params], 'method' => 'PUT']); $this->client->setSideload(null); return $response; }
/** * Incremental ticket exports with a supplied start_time * * @param array $params * * @throws MissingParametersException * @throws ResponseException * @throws \Exception * @return mixed */ public function export(array $params) { if (!$params['start_time']) { throw new MissingParametersException(__METHOD__, ['start_time']); } $queryParams = ["start_time" => $params["start_time"]]; $response = Http::send($this->client, $this->getRoute('export'), ["queryParams" => $queryParams]); return $response; }
/** * Wrapper for common GET requests * * @param $route * @param array $params * * @return \stdClass | null * @throws ResponseException * @throws \Exception */ private function sendGetRequest($route, array $params = []) { $response = Http::send($this->client, $this->getRoute($route, $params), ['queryParams' => $params]); return $response; }
/** * This is a helper method to do a delete request. * * @param $endpoint * * @return null * @throws Exceptions\ApiResponseException */ public function delete($endpoint) { $response = Http::send($this, $endpoint, ['method' => 'DELETE']); return $response; }
/** * Requests autocomplete for users * * @param array $params * * @throws ResponseException * @throws \Exception * @return mixed */ public function autocomplete(array $params) { $response = Http::send($this->client, $this->getRoute(__FUNCTION__), ['method' => 'POST', 'queryParams' => $params]); return $response; }
/** * Delete a resource * * @param $token * * @return bool * @throws MissingParametersException * @throws \Exception * @throws \Zendesk\API\Exceptions\ResponseException */ public function deleteUpload($token) { $response = Http::send($this->client, $this->getRoute(__FUNCTION__, ['token' => $token]), ['method' => 'DELETE']); return $response; }
/** * This makes a `PUT` request to the endpoint defined by the $callingMethod parameter. * * @param string $callingMethod * @param array $params * * @return array * @throws MissingParametersException * @throws \Exception * @throws \Zendesk\API\Exceptions\ApiResponseException * @throws \Zendesk\API\Exceptions\AuthException */ private function makePutRequest($callingMethod, $params = []) { $this->addUserIdToRouteParams($params); if (isset($params['id'])) { $id = $params['id']; } else { $id = $this->getChainedParameter(self::class); } if (empty($id)) { throw new MissingParametersException(__METHOD__, ['id']); } $response = Http::send($this->client, $this->getRoute($callingMethod, ['id' => $id]), ['method' => 'PUT']); return $response; }
/** * Reorder user fields * * @param array $params * * @return mixed */ public function reorder(array $params) { $postFields = ['user_field_ids' => $params]; $response = Http::send($this->client, $this->getRoute(__FUNCTION__), ['postFields' => $postFields, 'method' => 'PUT']); return $response; }
/** * @param array $params * * @throws MissingParametersException * @throws ResponseException * @return Tickets */ public function merge(array $params = []) { $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]); if (!$this->hasKeys($params, ['id', 'ids'])) { throw new MissingParametersException(__METHOD__, ['id', 'ids']); } $route = $this->getRoute(__FUNCTION__, ['id' => $params['id']]); unset($params['id']); $response = Http::send($this->client, $route, ['method' => 'POST', 'postFields' => $params]); return $response; }
public function testPutRequestWithContentType() { $response = Http::send($this->client, 'tickets.json', ['check' => 1], 'PUT', 'application/x-www-form-urlencoded'); $data = new \StdClass(); $data->check = 1; $this->assertEquals(is_object($response), true, 'Should return an object'); $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'), 'Should be the correct url'); $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'PUT', 'Should be a PUT'); $this->assertEquals($response->{CURLOPT_POSTFIELDS}, $data, 'Should have POST data'); $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER}, 'Should contain a Accept header'); $this->assertContains('Content-Type: application/x-www-form-urlencoded', $response->{CURLOPT_HTTPHEADER}, 'Should contain a Content-Type header'); }
/** * Reorder Ticket forms * * @param array $ticketFormIds * * @throws ResponseException * @throws \Exception * @return mixed */ public function reorder(array $ticketFormIds) { $response = Http::send($this->client, $this->getRoute(__FUNCTION__), ['postFields' => ['ticket_form_ids' => $ticketFormIds], 'method' => 'PUT']); return $response; }