Reputation: 1141
I am exploring Zoho-invoice api and trying to integrate with my application. But i am stuck and cant find out what is the reason.
Please help :
This is how i am calling the API :
$fields = array(
'contact_name' => urlencode([name]),
'billing_address' => array('address' => urlencode([address]), 'city' => urlencode([city]), 'state' => urlencode([state]), 'zip' => urlencode([pincode]), 'country' => urlencode([country])),
'contact_person_id' => urlencode([id]),
'email' => urlencode([email])
);
$jsonData = json_encode($fields);
//Initialize connection
$ch = curl_init("https://invoice.zoho.com/api/v3/contacts?authtoken=[authtoken]&organization_id=[id]&JSONString={$jsonData}");
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, TRUE);//Regular post
//Execute cUrl session
$response = curl_exec($ch);
curl_close($ch);
I am sending correct auth-token and organization key.
But I am getting this error response :
"code":1048,"message":"Sorry, there was an internal error. Please contact [email protected] for assistance."
Any help will be appreciated. Thank you
Upvotes: 0
Views: 2861
Reputation: 129
I've created a sample PHP Class which creates Invoice in Zoho Invoice using Zoho Invoice API v3. You can find it on GitHub.
/**
* Sends the actual request to the REST webservice
*/
protected function sendRequest($url, $data, $type = 'POST') {
$jsonData = json_encode($this->urlencode_array($data));
if ($type == 'POST') {
$ch = curl_init("https://invoice.zoho.com/api/v3/{$url}?authtoken={$this->data['authtoken']}&organization_id={$this->data['organization_id']}&JSONString={$jsonData}");
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, TRUE);//Regular post
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json") );
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
} else {
$ch = curl_init("https://invoice.zoho.com/api/v3/{$url}?authtoken={$this->data['authtoken']}&organization_id={$this->data['organization_id']}&JSONString={$jsonData}");
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, FALSE);//Regular post
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json") );
}
$result = curl_exec($ch);
$result = json_decode($result);
// RM: IS not object, is not code 0?
if (is_object($result) === false || $result->code != 0) {
throw new AppException('Error creating estimate/invoice - '.print_r($result, true));
}
return $result;
}
Upvotes: 1
Reputation: 39375
I didn't see you posting your json data in your code. Add these with your code:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json") );
curl_setopt($ch, CURLOPT_POSTFIELDS,$jsonData);
Upvotes: 2