Fix 403 errors for API calls

Some Wix SDK methods return 403 Forbidden when called with a visitor or member context. This usually happens when the method needs higher permissions than the current identity has.

For example, you have a function that returns the 403 error:

Copy

In Wix-managed headless projects, fix this by moving the method call to an HTTP endpoint and wrapping the SDK method with auth.elevate(). This way the frontend calls the HTTP endpoint, and the endpoint calls the protected API on the backend.

Notes:

Step 1 | Create a backend endpoint

Create an HTTP endpoint in your project, for example:

  • src/pages/api/upload-image.ts

Step 2 | Import modules

In your endpoint file, import:

  • APIRoute from astro
  • auth from @wix/essentials
  • The SDK module that contains the method you need
Copy

Step 3 | Wrap the SDK method

Expose an endpoint that calls the API method you need:

Copy

Wrap the method with auth.elevate() before calling it:

Copy

Step 4 | Call the endpoint from your frontend

From frontend code, send a request to your endpoint:

Copy

Note: This example is applicable for headless projects only. To call the endpoint in apps, see Elevate API Call Permissions.

See also

Did this help?