web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archive)
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
I have the same question (0)

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

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard > 🔒Ι Microsoft Dynamics CRM (Archived)

Featured topics

Product updates

Dynamics 365 release plans