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:
In the api.ts
file of your backend API extension, import the auth
submodule from the Essentials SDK:
In the GET
endpoint, call getTokenInfo()
, which extracts instanceId
from the access token:
Use the instanceId
and return the relevant data.
Note: Access tokens sent from site widgets have a site visitor or member identity. If you want to call getAppInstance()
, 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 Site Widget Extension in the CLI. If you already have a site widget, skip to the next step.
In the element.tsx
file of your site widget extension, import the httpClient
submodule from the Essentials SDK:
Call fetchWithAuth()
to send a request to your backend with a Wix access token:
Tip: To get the app instance ID in the settings panel, call fetchWithAuth()
from your panel.tsx
file.
The following sections contain example backend and frontend code for retrieving the app instance ID from a custom element.
The following example is based on a CLI backend API extension called get-instance
.
The following example creates a custom element to display the mock instance data from the get-instance
endpoint.