/** * The accounts * @param int|null $limit Optional parameter: Maximum number of results to return in the response. * @param int|null $page Optional parameter: Zero based offset index for the results. e.g. 0 would start at the first result and 10 would start at the eleventh result. * @return mixed response from the API call*/ public function getAll($limit = NULL, $page = NULL) { //the base uri for api requests $queryBuilder = Configuration::$BASEURI; //prepare query string for API call $queryBuilder = $queryBuilder . '/accounts'; //process optional query parameters APIHelper::appendUrlWithQueryParameters($queryBuilder, array('limit' => null != $limit ? $limit : 10, 'page' => null != $page ? $page : 1)); //validate and preprocess url $queryUrl = APIHelper::cleanUrl($queryBuilder); //prepare headers $headers = array('user-agent' => 'APIMATIC 2.0', 'Accept' => 'application/json', 'X-API-TOKEN' => $this->xAPITOKEN); //prepare API request $request = Unirest::get($queryUrl, $headers); //and invoke the API call request to fetch the response $response = Unirest::getResponse($request); //Error handling using HTTP status codes if ($response->code == 403) { throw new APIException('User not authorized to perform the operation', 403); } else { if ($response->code < 200 || $response->code > 206) { //[200,206] = HTTP OK throw new APIException("HTTP Response Not OK", $response->code); } } return $response->body; }