Cert++
Close

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:

  1. A Bearer token. For a JWT, the client ID is the issuer claim. For OAuth, the client ID is resolved from Account Manager.
  2. The client_id request parameter.
  3. The x-dw-client-id header.

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.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers. 796 members and growing.