For security reasons, the app instance ID isn’t directly accessible in site widgets or settings panels. Instead, you can securely extract it by sending a Wix access token to a backend API. The backend can decode the token, retrieve the instance ID, and perform any necessary business logic.
This article explains how to:
To securely identify the app instance:
Expose a backend API. You can build and deploy your backend API using any framework. The examples in this article are based on a Node.js server.
In your backend API code, get the Wix access token from the authorization
header:
Use the access token to call Get Token Info, which extracts instanceId
from the token.
Note: Access tokens sent from site widgets have a site visitor or member identity. If you want to call Get App Instance (SDK | REST), you'd need to elevate permissions:
To send the app instance ID to your backend, include a Wix access token in the request.
Add a self-hosted site widget extension with a custom element. If you already have a site widget, skip to the next step.
In your custom element code, initialize a WixClient
with the site authentication and host configuration:
Add the following line to the constructor of your custom element class to inject the Wix access token:
Import the httpClient
submodule from the Essentials SDK:
Call fetchWithAuth()
to send the access token to your backend:
Tip: To get the app instance ID in the settings panel, initialize a WixClient
with the editor authentication and host configuration. Then, call fetchWithAuth()
.
The following sections contain example backend and frontend code for retrieving the app instance ID from a custom element.
The following example creates a Node.js Express API called get-instance
.
The following example creates a custom element to display the mock instance data from the get-instance
endpoint.