Encoding XML string on Zoho insertRecord
Having trouble appending an XML string to the insertRecords URL to submit a record to Zoho via a third party tool (HubSpot). In the example below, the $lead->publicLeadLink contains variables separated by an ampersand (&) which is breaking the $insertURL string. I believe I am encoding it correctly but am not sure if Zoho already has an encoding/decoding process on the post page that I am conflicting with. Please help.
- $xml = '<Leads><row%20no=\'1\'><FL%20val=\'HubSpot%20GUID\'>'.urlencode($lead->guid).'</FL><FL%20val=\'Lead%20Owner\'></FL><FL%20val=\'First%20Name\'>'.urlencode($lead->firstName).'</FL><FL%20val=\'Last%20Name\'>'.urlencode($lead->lastName).'</FL><FL%20val=\'Designation\'>'.urlencode($lead->jobTitle).'</FL><FL%20val=\'Email\'>'.urlencode($lead->email).'</FL><FL%20val=\'Company\'>'.urlencode($lead->company).'</FL><FL%20val=\'Website\'>'.urlencode($lead->website).'</FL><FL%20val=\'Found%20Site%20Via\'>'.urlencode($lead->foundVia).'</FL><FL%20val=\'Hubspot%20Lead%20Intelligence\'>'.urlencode($lead->publicLeadLink).'</FL></row></Leads>';
- $insertURL = 'http://crm.zoho.com/crm/private/xml/Leads/insertRecords?&newFormat=1&duplicateCheck=2&apikey=' . $zoho_apikey . '&ticket=' . $zohoTicket . '&xmlData=' . $xml;
- //Next, perform the passing of the lead into Zoho using cURL.
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $insertURL);
- //This URL will automatically check the lead record's email address and de-duplicate on this value (the 'duplicateCheck' parameter).
- //If the lead email is found, the lead from HubSpot will not be added or updated. If you would like to update the lead information, set the 'duplicateCheck' parameter to '2' instead of '1'.
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
- $output = curl_exec($ch);
- curl_close($ch);
** The record fails to be inserted when there is an ampersand (&) in the $lead->company field as well.