我想使用/ using更新Contact
实体的firstname
字段。PATCH
PUT
HttpClient
我已经尝试过使用PATCH
联系人的GUID
. 但是,如果我尝试使用以下 URL:
baseURL/联系人(myorg_contactnumber='113')
baseURL/联系人('113')
baseURL/联系人(myorg_contactnumber="113")
但它抛出Bad Request
错误。
我想使用/ using更新Contact
实体的firstname
字段。PATCH
PUT
HttpClient
我已经尝试过使用PATCH
联系人的GUID
. 但是,如果我尝试使用以下 URL:
baseURL/联系人(myorg_contactnumber='113')
baseURL/联系人('113')
baseURL/联系人(myorg_contactnumber="113")
但它抛出Bad Request
错误。
没有看到你的代码,就像 Jatin 说的那样 - 可能唯一的失误可能是Alternate key setup。
像这样的 PATCH 请求的好处是,默认情况下,如果记录存在,它将更新记录,如果记录不存在,它将创建记录。
url: /api/data/v8.2/contacts(new_alternatekey='12345')
method: PATCH
body: {
"name": "Alternate key contact updated"
}
您还标记了 C#,因此请尝试以下操作:
JObject contact1Add = new JObject();
contact1Add.Add("firstname", "Jack");
HttpRequestMessage updateRequest1 = new HttpRequestMessage(
new HttpMethod("PATCH"), contact1Uri);
updateRequest1.Content = new StringContent(contact1Add.ToString(),
Encoding.UTF8, "application/json");
HttpResponseMessage updateResponse1 =
await httpClient.SendAsync(updateRequest1);
if (updateResponse1.StatusCode == HttpStatusCode.NoContent) //204
{
Console.WriteLine("Contact '{0} {1}' updated with " +
"firstname", contact1.GetValue("firstname"),
contact1.GetValue("lastname"));
}
else
{
Console.WriteLine("Failed to update contact for reason: {0}",
updateResponse1.ReasonPhrase);
throw new CrmHttpResponseException(updateResponse1.Content);
}