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 frontend environments.
To identify the app instance in frontend environments:
instanceId
and apply the necessary business logic.Note: The method for sending the access token depends on whether your frontend is Wix-hosted or self-hosted, as Wix-hosted extensions automatically handle authentication.
This article focuses on how to send an access token to your backend. To learn how to decode it, see Identify the App Instance in Backend Environments.
Warning: Don't trust an instanceId
sent to your backend as plain text, as it can be manipulated by an attacker.
Wix-hosted frontend extensions include those built with the CLI or Blocks.
Frontend extensions built with the CLI can identify the app instance using a CLI web method extension or CLI API extension. Learn more about differences between web methods and API extensions.
To identify the app instance using a web method:
To identify the app instance using an API extension:
Implement an API extension to decode a Wix access token, based on the API extension backend example.
Install Essentials.
Call your API from your frontend code using httpClient.fetchWithAuth()
.
Frontend extensions built with Blocks can identify the app instance using a Blocks backend function. To do so:
Alternatively, you can use the getDecodedAppInstance()
Velo API.
Note: If you can't use Essentials, you can extract the Wix access token from the authorization
header and send it to Get Token Info.
For self-hosted site extensions, the method of sending an access token to your backend varies depending on the technology:
Important: The backend is responsible for decoding the token and identifying the app instance. For more information, see Identify the App Instance in Backend Environments.
To identify the app instance from a self-hosted custom element:
site
host and authentication.fetchWithAuth()
.The following example demonstrates only the frontend logic.
To identify the app instance from a self-hosted embedded script:
site
host and authentication.fetchWithAuth()
.The following examples demonstrate only the frontend logic.
ECMAScript Module
Standard
Wix provides iframes with an encoded instance
query parameter. This is relevant for self-hosted dashboard pages, dashboard plugins, settings panels, and external links.
To identify the app instance from an iframe:
instance
query parameter from the URL.instance
value as the token
to Token Info.instanceId
to create an app access token and call Get App Instance.Note: If your iframe content runs client-side JavaScript and needs to communicate with your server, create a Wix Client and call fetchWithAuth()
to include a Wix access token in the request.