Hi, what about improving the getRecords method to add default values for page and per_page params and the fields parameter like the one below? It should work and shouldn't affect backward compatibility.
It would be great to have better documentation of the SDK and several examples.
- public function getRecords($cvId = null, $sortByField = null, $sortOrder = null, $page = 1, $perPage = 200, $customHeaders = null, $fields= null)
- /*
- * Optional parameters:
- * cvId = custom view id (integer)
- * sortByField = Field API Name (string)
- * sortOrder = asc - ascending order || desc - descending order
- * page = Positive Integer values only default is 1
- * per_page = Positive Integer values only default is 200
- * customHeaders = string
- * fields = Multiple field API names, comma separated. For example: Last_Name,Email (string)
- *
- * I put fields as last to avoid breaking backward compatibility. "converted" and "approved" might be added too.
- */
- {
- try {
- $this->urlPath = $this->module->getAPIName();
- $this->requestMethod = APIConstants::REQUEST_METHOD_GET;
- $this->addHeader("Content-Type", "application/json");
- if ($customHeaders != null) {
- foreach ($customHeaders as $key => $value) {
- $this->addHeader($key, $value);
- }
- }
- if ($fields != null) {
- $this->addParam("fields", (string) $fields);
- }
- if ($cvId != null) {
- $this->addParam("cvid", (integer) $cvId);
- }
- if ($sortByField != null) {
- $this->addParam("sort_by", $sortByField);
- }
- if ($sortOrder != null) {
- $this->addParam("sort_order", $sortOrder);
- }
- $this->addParam("page", (integer) $page);
- $this->addParam("per_page", (integer) $perPage);
- $responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
- $responseJSON = $responseInstance->getResponseJSON();
- $records = $responseJSON["data"];
- $recordsList = array();
- foreach ($records as $record) {
- $recordInstance = ZCRMRecord::getInstance($this->module->getAPIName(), $record["id"]);
- EntityAPIHandler::getInstance($recordInstance)->setRecordProperties($record);
- array_push($recordsList, $recordInstance);
- }
- $responseInstance->setData($recordsList);
- return $responseInstance;
- } catch (ZCRMException $exception) {
- APIExceptionHandler::logException($exception);
- throw $exception;
- }
- }