-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Code generates a 400 error. This seems to be due to a missing CURLOPT_POSTFIELDS. However, if you try to post the access token, losing lead, and the merge in crm values as posted fields, you will get 1003 errors.
This will generate a 1003 Error
public function postData(){ $url = $this->host . "/rest/v1/leads/" . $this->id ."/merge.json"; $fields = array( 'access_token' => urlencode($this->getToken()), 'leadIds' => urlencode($this::csvString($this->leadIds)), 'mergeInCRM' => urlencode('true') ); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json','Content-Type: application/json')); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_getinfo($ch); $response = curl_exec($ch); return $response; }
Sending an empty set of post fields gets rid of the 400 error
public function postData(){ $url = $url = $this->host . "/rest/v1/leads/" . $this->id ."/merge.json?access_token=" . $this->getToken() . "&leadIds=" . $this::csvString($this->leadIds); $fields = array(); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json','Content-Type: application/json')); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_getinfo($ch); $response = curl_exec($ch); return $response; }
Sending without the mergeInCRM parameter, returns a success. With the mergeInCRM set to true I get a 611 error when merging a contact to a lead. The call will convert the lead to a contact and assign it a new marketo ID. If you run the merge again with the existing contact and the new contact, the contacts are merged in Marketo, but not in Salesforce. It seems the API is just as poor at merging as within the marketo platform natively. It's best just to merge leads/contacts within SF.