Hello,
I am trying to insert a Sales Order into Zoho CRM via the XML API, however all i get is the 4500 Generic Error, as far as i can tell it all looks ok, the ticket is retrieved successfully and all mandatory fields are specified for a SalesOrder according to http://zohocrm.wiki.zoho.com/Zoho-CRM---Standard-Fields.html#Sales_Orders those that are lookup fields reference valid items, could anyone please offer any advice?
Below is the code being used, where product name and account name reference valid data, identifiable data has been removed from the below code.
Many Thanks,
- $zoho_crm_ticket = false;
$zohodata = "
<SalesOrders>
<row no=\"1\">
<fieldlabel value=\"Subject\">Web Sales Order: " . date('d/m/Y') . "</fieldlabel>
<fieldlabel value=\"Account Name\">ACCOUNTNAME</fieldlabel>
<fieldlabel value=\"Product Name\">Site Licence</fieldlabel>
<fieldlabel value=\"Quantity\">1.0</fieldlabel>
<fieldlabel value=\"Unit Price\">0.0</fieldlabel>
<fieldlabel value=\"List Price\">123.0</fieldlabel>
</row>
</SalesOrders>
";
die("Response:" .
zoho_crm_request("http://crm.zoho.com/crm/private/xml/SalesOrders/insertRecords?apikey=[APIKEY]&ticket=[TICKET]",array("xmlData"=>$zohodata)));
function zoho_crm_get_ticket() {
$zoho_crm_username = "...ZOHO-USER-NAME...";
$zoho_crm_password = "...ZOHO-PASSWORD...";
$url =
"https://accounts.zoho.com/login?servicename=ZohoCRM&FROM_AGENT=true&LOGIN_ID=$zoho_crm_username&PASSWORD=$zoho_crm_password";
$zoho_crm_username==$zoho_crm_password=$zoho_crm_apikey="";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$count = preg_match_all("|^TICKET=(.*)$|m",$result,$matches,PREG_PATTERN_ORDER);
if ($count > 0) {
return $matches[1][0];
} else {
return false;
}
}
function zoho_crm_request( $url, $postData ) {
global $zoho_crm_ticket;
$zoho_crm_apikey = '....API KEY....';
if ( $zoho_crm_ticket == false ) {
if ( !($localTicket = zoho_crm_get_ticket()) ) return false;
$zoho_crm_ticket = $localTicket;
}
$url = str_replace( array("[APIKEY]","[TICKET]"), array($zoho_crm_apikey,$zoho_crm_ticket), $url );
/* $postData['apikey']=$zoho_crm_apikey; DOESNT APPEAR TO PICK THESE UP FROM POST DATA
$postData['ticket']=$zoho_crm_ticket; */
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, TRUE );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postData );
echo "\nSending Request to: \n" . $url;
$result = curl_exec($ch);
if (curl_errno($ch)>0) { echo curl_error($ch); return false; }
if ($result=='') return false;
return $result;
}