Identify the App Instance in Backend Environments

When your app is installed on multiple Wix sites, you need a way to determine which site is making a request. This is done using the app instance.

In some cases, you may only need the instanceId to query your database and perform business logic. In other cases, you may want to fetch additional data about the app instance from Wix. This article covers both approaches across different backend environments.

CLI web method extension

For web methods, you can:

The following example logs the instanceId, and then elevates the access token to make a request to getAppInstance(). Elevation is necessary because web methods are called from frontend code, and frontend access tokens are associated with site visitors or members, who lack permission to retrieve instance data.

Copy

CLI API extension

For CLI API extensions, you can:

Important: For this to work, you must send a Wix access token from the frontend to your API extension. This can be done with httpClient.fetchWithAuth(), as explained in the Wix-hosted frontend example.

The following example logs the instanceId, and then elevates the access token to make a request to getAppInstance(). Elevation is necessary because web methods are called from frontend code, and frontend access tokens are associated with site visitors or members, who lack permission to instance data.

Copy

Blocks backend function

For Blocks backend functions, you can:

The following example logs the instanceId, and then elevates the access token to make a request to getAppInstance(). Elevation is necessary because Blocks backend functions are called from frontend code, and frontend access tokens are associated with site visitors or members, who lack permission to instance data.

Copy

Note: If you're not able to use Essentials, you can extract the Wix access token from the authorization header and send it to Get Token Info.

Self-hosted backend using the JavaScript SDK

For a self-hosted backend using the SDK, you can:

The following example creates a Node.js Express API called get-instance-data. The API receives an access token from the frontend (which has a visitor or member identity), decodes the token and logs the instanceId, and then creates a client with elevated permissions to fetch the app instance data.

Copy

Self-hosted backend using the REST API

For a self-hosted backend using the REST API, you can:

The following example creates a Node.js Express API called get-instance-data. The API receives an access token from the frontend (which has a visitor or member identity), decodes the token and logs the instanceId, and then uses the instanceId to create an access token with app permissions to fetch the instance data.

Copy

Service plugin extension

For service plugins, get instanceId from the metadata of the service plugin call.

The following example is based on the additional fees service plugin.

Copy

CLI event extension

For CLI event extensions, get instanceId from the metadata of the event.

The following example is based on onPostCreated().

Copy
Did this help?