rest - How do I make this Salesforce cURL request in PHP? -
i'm using php make curl requests salesforce's rest api.
i've got of requests need make figured out, i'm not sure how convert following curl
command on following salesforce api page curl request in php:
curl https://yourinstance.salesforce.com/services/data/v20.0/sobjects/account/customextidfield__c/11999 -h "authorization: bearer token" -h "content-type: application/json" -d @newrecord.json -x patch
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm
i know that -h
option headers, i'm handing following:
curl_setopt($ch, curlopt_httpheader, $headers);
and think -x patch
part can accomplished following php curl option:
curl_setopt($ch, curlopt_customrequest, 'patch');
however, how handle -d @newrecord.json
part in php curl?
thanks.
what doing -d @newrecord.json
uploading (json) file endpoint use. replicate in php, need pass array file
element curopt_postfields
, this:
$file = [ "file" => "@newrecord.json"; ]; curl_setopt($ch, curlopt_postfields, $file);
make sure give correct file path. can use realpath()
aid this.
alternatively, send json encoded data:
$data = [ "site" => "stack overflow", "help" => true, ]; $jsondata = json_encode($data); curl_setopt($ch, curlopt_postfields, $jsondata);
don't forget set content-type: application/json
header!
lastly, guess patch
request correct:
curl_setopt($ch, curlopt_customrequest, 'patch');
Comments
Post a Comment