Uploading a file into Zoho via API using CURL

The file upload via API into Zoho can be a problem for PHP developers. In this post we introduce a simple file uploading system. Before uploading a file via API, review the request parameters and their value type.
Request Parameters
Parameter | Data Type | Description |
authtoken* | String | Encrypted alphanumeric string to authenticate your Zoho credentials. |
scope* | String | Specify the value as crmapi |
id* | String | Specify unique ID of the record to which the file has to be attached. |
content* | FileInputStream | Pass the File Input Stream of the file |
* – Mandatory parameter
Important Note:
- The total file size should not exceed 20 MB.
- Your program can request only 15 uploadFile calls per 5 min. If API User requests more than 15 calls, system will block the API access for 15 minutes.
- If the size exceeds 20 MB, you will receive the following error message: “File size should not exceed 20 MB”.
- The attached file will be available under the Attachments section in the Record Details Page.
- Files can be attached to records in all modules except Reports, Dashboards and Forecasts.
Some analysis regarding the parameter:
authtoken: Always send this parameter appending with the request url irrespective with your request method whether get or post (e.g.: REQUEST_URL?AUTHTOKEN=**********). Otherwise you will get 4834 => Invalid Ticket Error.
scope: Like the authtoken, also send this parameter appending with your request url irrespective with your request method.
id: This parameter should go as one of the fields of CURL postfields. Remember one thing, when providing this parameter value please exclude “zcrm_” prefix from your Zoho ID. For example, if your Zoho record id is zcrm_807524000000244811 then just provide 807524000000244811 as the value of this parameter.
content: This is the most important part. DO NOT READ THE FILE CONTENT USING PHP FUNCTIONS (LIKE: file_get_contents() / stream_get_contents() / fread() ). INSTEAD, STORE THE FILE INTO YOUR FILE SYSTEM AND PROVIDE THE FILE URL AS A STRING PREPENDING AN ‘@’ SIGN BEFORE THE URL AND USE THIS PARAMETER AS ONE OF THE CURL POSTFIELDS PARAMETER (E.G.: ‘@/PATH/TO/YOUR/FILE’). This ‘@’ sign will tell the curl not to send the url but to send the file stream instead.
Sample Code for Zoho for this file upload.
For more help with CURL upload zoho API please visit:
- https://www.zoho.com/crm/help/api/error-messages.html
- https://www.zoho.com/crm/help/api/uploadfile.html
The web development experts at Digital Firefly Marketing can help you with CURL upload Zoho API issues and an array of other development matters. Contact us to learn more about getting your site assessed and what we can do for you.