I am trying to attach a file to a Zoho CRM Account page using the ZohoCRM API and not having any success. I am using Curl and PHP5.3 (no curl_file_create, so using hand rolled version).
In my log I get the following report
Curl::post
Url: https://crm.zoho.com/crm/private/json/Accounts/uploadFile?authtoken=MY_TOKEN&scope=crmapi
Params: Array(
[content] => @/tmp/b2d-JbJvMY;filename=b2d-JbJvMY;type=application/pdf
[id] => MY_ACCOUNT_ID
)
I get no response from ZohoCRM and the file is definitely not attached to the target Account record. What am I doing wrong?
Here's some excerpts from my code that may help or hinder: ... other methods from my ZohoAPI class such as getSearchRecords appear to be working fine...
class Curl {
...
protected static function post($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
...
}
class ZohoAPI extends Curl {
....
protected function apiPost($url, $params) {
$url .= "?authtoken={$this->token}&scope={$this->scope}";
$apiParams = empty($params) ? '' : $params;
return $this->post($url, $apiParams);
}
...
public function uploadFile($module='Accounts', $zohoId = '', $file ) {
$url = "{$this->apiUrl}/{$this->mode}/{$module}/uploadFile";
$params = array(
'content' => curl_file_create($file, 'application/pdf' , basename( $file, '.pdf')),
'id' => $zohoId
);
return $this->apiPost($url, $params);
}
...
}