1
votes

I'm using Dynamics CRM 2016 Online and I want to update an entity (a contact for example) using the Web API (odata 4.0) endpoint.

I use Fiddler to test the request. Here are the details of the request :

PATCH https://XXXXXXXXXXX/api/data/v8.0/contacts(6b902ae1-19ed-e511-80e3-5065f3890551)
User-Agent: Fiddler
Host: XXXXXXXXX
Content-Length: 54
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Content-Type: application/json
Authorization: Bearer XXXXXXXX

{
    "firstname": "John",
    "lastname": "Doe"
}

It works well. The problem is that the client does not support the PATCH verb.

An odata endpoint can handle this limitation by using POST and a additional HTTP header. Quote from the documentation :

In order to help work-around this limitation, OData servers can support method tunneling through POST. The methods that can be executed through tunneling are MERGE, PUT and DELETE.

To issue a request with method tunneling a client sets up a request with body and headers as needed, but uses POST as the HTTP method instead of the actual required one. It then adds one more header, "X-HTTP-Method", and gives it the value MERGE, PUT or DELETE.

Servers must check if POST requests have the X-HTTP-Method header set to one of the valid values and if so execute the rest of the request as if the header value was the actual HTTP method for it.

But when I try to execute the same request using POST instead of PATCH and with the additional header, I receive a error :

message=Unmapped Request found, PathTemplate:~/entityset/key, HttpVerb:POST

I also try the X-HTTP-Method-Override header as described here but same result.

Is there a mistake from my side or the endpoint does not support this feature ? Thanks.

1
CRM's Web API endpoint is definitely not a complete implementation of the OData protocol, so if your POST request received that response, then that's a strong indication that the endpoint doesn't support that part of the protocol. :/Polshgiant

1 Answers

1
votes

Use PATCH (but you say this one is not being supported).

Use PUT (note with PUT you have to specify the attribute URL/{attribute}, which forces you to make for each attribute a PUT call, not the perfect way but its something)

This worked for me instead of a POST.

https://msdn.microsoft.com/en-us/library/mt607664.aspx