Authenticate Using OAuth

This article explains how to authenticate API calls to Wix using OAuth.

Important: Extensions built with Wix Blocks or the Wix CLI handle authentication automatically.

Step 1 | Get app credentials and instance ID

To authenticate, you need the following information:

  • App ID: Find it on the OAuth page of your app's dashboard.
  • App secret: Find it on the OAuth page of your app's dashboard. Keep this value confidential.
  • App instance ID: The unique identifier (instanceId) for your app on a site.

There are different ways to get the instanceId, depending on your app's logic. The most common methods for getting it to generate an access token are:

To learn more, see About App Instances.

Step 2 | Make an authenticated API request

The authentication process varies depending on whether you use the JavaScript SDK or REST API.

JavaScript SDK

To make an authenticated API request with the JavaScript SDK in a self-hosted extension:

  1. Create a WixClient using the AppStrategy.

    Copy
  2. Make an API request. The client automatically obtains and includes the access token in the Authorization header. For example, call queryProducts().

    Copy

Important: The Wix CLI also uses the JavaScript SDK but handles authentication automatically. To make API requests from CLI extensions, use the httpClient.

REST API

To make an authenticated API request with the REST API:

  1. Send a request to Create Access Token. Include your app ID, app secret, and instanceId in the HTTP body.

    Copy
  2. Store the access_token from the response. The token is valid for 4 hours.

  3. Make an API request by including the access_token in the Authorization header. For example, call Query Products.

    Copy

Migrate from custom authentication (legacy)

To migrate from custom authentication to OAuth:

  1. Replace requests to Refresh an Access Token with Create an Access Token.
  2. Make sure that you have a method to get instanceId as described in step 1. We recommend subscribing to the App Instance Installed webhook.

See also

Did this help?