function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ethanoneethanone 

Updating a record with php and rest api

I have a similar problem. I'm trying to update a field (Research_Reason__c) on a custom object (lda_Opportunity__c). I can query a record fine, but updating is a little different and I can't figure it out.

Here is my function:
function FlagFixDeal($id,$reason,$researchtime){
$access_token = $_SESSION['access_token'];
        $instance_url = $_SESSION['instance_url'];

$content = json_encode(array("Research_Reason__c" => $reason));
$url = "$instance_url/services/data/v20.0/sobject/lda_Opportunity__c/$id";

    $curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Authorization: OAuth $access_token","Content-type: application/json"));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status != 204) {
  die("Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) .", curl_errno " . curl_errno($curl));
}

echo "HTTP status $status updating deal.<br /><br />";
curl_close($curl);
}


Error I'm getting is:
Error: call to URL https://na19.salesforce.com/services/data/v20.0/sobject/lda_Opportunity__c/a0Oa000000LAkarEAD failed with status 404, curl_error , curl_errno 0

Thanks in advance for any help you can provide.
Best Answer chosen by ethanone
ShashForceShashForce
Hi,

The REST resource URL should have "sobjects" instead of "sobject". Something like this:

$url = "$instance_url/services/data/v20.0/sobjects/lda_Opportunity__c/$id";

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank

All Answers

ShashForceShashForce
Hi,

The REST resource URL should have "sobjects" instead of "sobject". Something like this:

$url = "$instance_url/services/data/v20.0/sobjects/lda_Opportunity__c/$id";

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank
This was selected as the best answer
ethanoneethanone
Great! Thank you!
ramji bhramji bh
Hi,

I am also getting the below error when we use "PATCH"

Error: call to URL https://ap4.salesforce.com/services/data/v20.0/sobjects/Contact/0036F000030xg6nQAA failed with status 204, response , curl_error , curl_errno 0

how to resolve the issue.

Thanks in advance.