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.
For web methods, you can:
instanceId by calling auth.getTokenInfo().getAppInstance to auth.elevate() and calling the elevated function.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.
For CLI API extensions, you can:
instanceId by calling auth.getTokenInfo().getAppInstance to auth.elevate() and calling the elevated function.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.
For Blocks backend functions, you can:
instanceId by calling auth.getTokenInfo().getAppInstance to auth.elevate() and calling the elevated function.Then, you can call your Blocks backend function from your Blocks frontend code.
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.
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.
For a self-hosted backend using the SDK, you can:
instanceId by passing a Wix access token to Token Info.getAppInstance().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.
For a self-hosted backend using the REST API, you can:
instanceId by passing a Wix access token to Token Info.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.
For service plugins, get instanceId from the metadata of the service plugin call.
The following example is based on the additional fees service plugin.
For CLI event extensions, get instanceId from the metadata of the event.
The following example is based on onPostCreated().