Your concurrency errors are happening because optimistic locking was enabled without updating your API integration to handle the version control mechanism. Let me explain the complete solution:
Optimistic Locking Enabled:
When you enabled optimistic locking, D365 started tracking record versions using ETags. This prevents lost updates when multiple processes modify the same record. The system now requires proof that you’re working with the current version of each order before accepting updates.
API Payload Missing Version Field:
Your current payload doesn’t include any version information. The Order Management API needs the ETag value to validate that your update is based on the most recent record state. Here’s the corrected approach:
First, retrieve the order with its current ETag:
GET /data/SalesOrderHeadersV2(dataAreaId='USMF',SalesOrderNumber='SO-2025-0145')
Accept: application/json
The response includes the ETag in the header:
ETag: W/"JzEsNTYzNzE0NDU3Njsw"
Then use this ETag in your update request:
PATCH /data/SalesOrderHeadersV2(dataAreaId='USMF',SalesOrderNumber='SO-2025-0145')
If-Match: W/"JzEsNTYzNzE0NDU3Njsw"
Content-Type: application/json
{
"SalesStatus": "Delivered",
"DeliveryDate": "2025-02-08"
}
Order Status Update Endpoint Requirements:
The endpoint validates three things: (1) The If-Match header contains a valid current ETag, (2) The order hasn’t been modified since you retrieved the ETag, (3) The status transition is valid per your D365 workflow configuration.
Implementation Best Practices:
- Always GET before PATCH - never cache ETags
- Implement retry logic: If you get a 409, retrieve fresh ETag and retry the update
- Use exponential backoff for retries (wait 1s, then 2s, then 4s)
- Set a maximum retry count (typically 3 attempts)
- Log the ETag values for troubleshooting concurrency issues
- Consider using batch operations if updating multiple orders to reduce round trips
For High-Volume Scenarios:
If you’re processing many order updates, consider implementing a queue-based approach where each order update is atomic and retries are handled automatically. This prevents your integration from failing when concurrent updates occur from multiple sources (UI users, workflows, other integrations).
The 40% failure rate suggests you might have automated processes or multiple integration threads trying to update the same orders simultaneously. Review your D365 workflows and ensure only one process updates order status at a time.