使用REST API更新记录

时间:2019-10-04 11:20:47

标签: php rest salesforce integration

我正在进行PHP和Salesforce集成,我想使用PHP更新记录。

desired layout

我想在单击“跟进”按钮时更新Salesforce中的记录。 并尝试以下代码。

function update_account($id, $followup, $instance_url, $access_token) {
$url = "$instance_url/services/data/v20.0/sobjects/Contact/$id";


$content = json_encode(array("shivendra__FollowUp__c" => $followup));
echo $content;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
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 "<b>update_contact function</b>";
echo "HTTP status $status updating Contact<br/><br/>";

curl_close($curl);
}

但是出现错误:

  

{“ shivendra__FollowUp__c”:null}

     

[{“ errorCode”:“ METHOD_NOT_ALLOWED”,“ message”:“ HTTP方法'PATCH'不允许。允许的是HEAD,GET,POST”}]

     

错误:对URL https://shivendra-dev-ed.my.salesforce.com/services/data/v20.0/sobjects/Contact/的调用失败,状态为405,curl_error,curl_errno 0

1 个答案:

答案 0 :(得分:0)

尝试使用cURL的post方法,类似于此:

curl_setopt($ch, CURLOPT_POST, 1);