Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

WEB API: Update contact - The requested resource does not support http method 'PATCH'.

(2) ShareShare
ReportReport
Posted on by 2,664

Hi,

I try to use the web api to create a console app where I can update contacts.

I created a method to update contact:

UserDto userupd = new UserDto();
userupd.firstname = "Test11231";
userupd.lastname = "Test12112";
userupd.contactid = Guid.Parse("891330a0-274b-ec11-8c62-000d3ada7f0d");

string body = Newtonsoft.Json.JsonConvert.SerializeObject(userupd);
var userdetailAnswer = CrmRequest2(
new HttpMethod("PATCH"),
String.Format("{0}/{1}/contacts", "">xxxxxx.api.crm4.dynamics.com", "api/data/v9.2/"),
body)
.Result.Content.ReadAsStringAsync();

where CrmRequest2 is: 

public static async Task<HttpResponseMessage> CrmRequest2(HttpMethod httpMethod, string requestUri, string body = null)
{
// Acquiring Access Token
var accessToken = await AccessTokenGenerator();

var client = new HttpClient();
var message = new HttpRequestMessage(httpMethod, requestUri);

// OData related headers
message.Headers.Add("OData-MaxVersion", "4.0");
message.Headers.Add("OData-Version", "4.0");
message.Headers.Add("Prefer", "odata.include-annotations=\"*\"");
message.Headers.Add("Accept", "application/json");
// Passing AccessToken in Authentication header
message.Headers.Add("Authorization", $"Bearer {accessToken}");

// Adding body content in HTTP request
if (body != null)
message.Content = new StringContent(body, UnicodeEncoding.UTF8, "application/json");

HttpResponseMessage httpResponseResult =
client.SendAsync(message, HttpCompletionOption.ResponseContentRead).Result;

if (httpResponseResult != null)
{
IEnumerable<string> uri = null;
httpResponseResult.Headers.TryGetValues("OData-EntityId", out uri);
if (uri != null)
{
string entityId = uri.FirstOrDefault();
}
}

return await client.SendAsync(message);

}

When I execute the code, I have the error: 

The requested resource does not support http method 'PATCH'. 
Do you have any idea? 
thanks
Alessandro

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans