'Dynamics Web API BATCH POST vs PATCH (remove navigation property value)

I am attempting to Disassociate a reference a contact reference to a single-valued navigation property by setting the value to null.

This works when I call the web api directly:

PATCH https://mydynamics.crm.dynamics.com/api/data/v9.2/contacts(00000000-0000-0000-0000-000000000000)
{ "firstname": "John",
"lastname":"Doe",
"[email protected]": null,
"[email protected]": null,
"[email protected]": null
}
//[...other data omitted for brevity...]

So these lookup fields, lookup 1,2, and 3 would be reset to null (The association is removed).

We run a synchronization program that calls these operations in a batch and when this runs -- using the same payload -- the lookup fields fail to reset (although if I modified firstname or lastname - those fields would update). This is a POST batch call containing just the single PATCH operation in this case but it normally contains multiple operations. All documentation I can find states that PATCH with multiple operation should be a POST call but it didn't reset my lookups.

If I change the POST batch to a PATCH batch...then it works as expected and all fields are updated correctly including the lookups!

Why the difference between BATCH POST vs PATCH?!

  • Is is a bug in the API?
  • Is it because I only had a single operation in the batch? Would it work for multiple requests? (I didnt try).
  • Does using PATCH instead of POST have any negative affect on either a single operation or multiple operations? Suppose a DELETE operation was also in the batch for something? Microsoft says "Use a POST request to submit a batch operation that contains multiple requests. A batch request can include GET requests and change sets."
  • Why is the documentation lacking on this topic?

Any help is appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source