1

The aim of this code is to call post method apex rest using php curl. But I am getting an error of response [{"message":"Unexpected parameter encountered during deserialization: Last Name at [line:1, column:129]","errorCode":"JSON_PARSER_ERROR"}], curl_error , curl_errno 0" status: "failed" . Can anyone help me ?

PARAMETERS

$query = 'Event';

    $contactData = array(
        'eventId'       =>   $event_id,-->(String)'salesforce id'
        'appFormId'     =>   $form_id, --> (String)'salesforce id'
        'contactId'     =>   $sfcontact,---> (String)'salesforce id'
        'appData'       =>   $args --> (Array) {'name':'danryl','lastname':'carpio'}
     );

    $sf_helpers = new Test_Helpers();
    $response = $sf_helpers->SF_CREATE($query, $contactData);

HERE IS MY PHP CODE

public function SF_CREATE($query, $data){

    $curl = curl_init($this->instance_url . '/services/apexrest/' . $query);
    $content = json_encode($data);

    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Authorization: OAuth " . $this->access_token,"Content-type: application/json"));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

    $json_response = curl_exec($curl);

    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

APEX REST POST METHOD CODE

@RestResource(urlMapping='/Event/*')
global with sharing class AS_EventAndApplication {

@HttpPost
global static ResponseHandler post(String eventId, String appFormId, String  contactId, String appData)
{
       //insertion code goes here !
}
    return response;   
}

}

  • Normally, if you provide "name" then you wouldn't have to provide "lastname". Rename your first parameter to "firstname" and I think you'll be fine. – Sebastian Kessel Dec 3 '15 at 4:01
  • That parameters are dynamic.. I don't think that's the reason of throwing an exception.. Thanks by the way.. – Danryl Tigol Carpio Dec 3 '15 at 4:30
  • Nothing to be lost by trying... – Sebastian Kessel Dec 3 '15 at 4:31
  • yes . i will give it a try :) – Danryl Tigol Carpio Dec 3 '15 at 4:33
  • I don't. Know php, I'm just assuming based on what I know from SFDC behavior. – Sebastian Kessel Dec 3 '15 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.