Troubleshooting OCAPI requests rejected by client permissions
Key Takeaway
OCAPI grants nothing by default. To fix a 401 UnauthorizedWriteAccessException, add a resource entry whose resource_id matches the path, whose methods include the HTTP method, and whose write_attributes list the properties you send.
Open Commerce API (OCAPI) lets a client application reach only the resources it has been granted in the OCAPI settings. By default, nothing is granted. Each request must identify its client with a client ID. B2C Commerce rejects the request if that ID is missing or unknown, or if the client has no permission for the resource. To troubleshoot a rejected request, read the HTTP status and the exception type. Then fix the client ID, the permission JSON in Business Manager, or the URL scope.
How a request identifies its client
Every OCAPI request must carry a client ID. A request can send it in three ways. When a request sends more than one, they take precedence in this order:
- A Bearer token. For a JWT, the client ID is the issuer claim. For OAuth, the client ID is resolved from Account Manager.
- The
client_idrequest parameter. - The
x-dw-client-idheader.
The client ID must also be enabled in Account Manager. Client IDs are cached for a time before they're revalidated, so enabling or disabling one doesn't change its status immediately.
Demo client IDs work only on sandbox instances.