Reputation: 439
Objetcive :trying to create a file in zoho workdrive, using php-curl
note: i have checked the oauth & i am using right oauth. also, i am using the correct parent id .
error-recieved : {"errors":[{"id":"F000","title":"General
Exception"}]}
code used:
work_drive_create_file($oauth);
function work_drive_create_file($oauth){
$apiUrl = "https://workdrive.zoho.com/api/v1/files";
$data ='{
"data": {
"attributes": {
"name": "Untitled Spreadsheet",
"service_type": "zohosheet",
"parent_id": "0nk78318a1771da934f22939e4a00d8aab225"
},
"type": "files"
}
}';
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
sprintf('Authorization: Zoho-oauthtoken %s', $oauth)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS ,$data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$response = curl_exec($ch);
print_r(json_decode($response));
curl_close($ch);
return $response;
}
also i would like to know the value for "service-type" if its a document in place of zohosheet.
Upvotes: 1
Views: 1250
Reputation: 44
@Rishabh Kushwaha You have missed to set User agent Header in the Rest API.
As Per RFC 7231:
A user agent SHOULD send a User-Agent field in each request unless specifically configured not to do so.
You could use a simple user agent header like User-Agent: “PHP 5.7.1”. Try with proper user agent header and rest api will work as expected. This should be useful to monitor the source of request originates and also make it easy to find your tests in the access stats log.
Upvotes: 2
Reputation: 44
api/v1/files is the endpoint to create a file. so the api call looks like the one shown below:
$apiUrl = https://workdrive.zoho.com/api/v1/files
To create a Document :
service_type = “zw”
To create a presentation
service_type=“zohoshow”
You'll find answers to most of your questions on our API documentation here.
Upvotes: 0