Important: This strategy is for administrative operations at the site or account level. For security purposes, a request made from the browser using an API key will encounter errors attributed to cross-origin resource sharing (CORS) restrictions. To learn more, see Authorization Strategies.
This authentication strategy is used along with a Wix Client
to authenticate API calls using an API Key.
When using this authentication strategy for an API request, the requester's identity is that of the corresponding API Key. The permissions associated with this API Key are set in the Dev Center.
Creates an authentication strategy object that uses an API key.
Name | Type | Description |
---|---|---|
apiKey | string | The API key to use for authentication. |
accountId | string | Optional. The account ID to use for authentication when calling account-level APIs. |
siteId | string | Optional. The site ID to use for authentication when calling site-level APIs. |
Note:
You must provide either a siteId
or accountId
value, depending on whether you're calling site-level or account-level functionality. To learn how to retrieve these values, see Site and Account IDs.
ApiKeyStrategy
Sets the account ID to use along with an API Key when authenticating.
Use an account ID for authentication when you need to call account-level APIs.
Set the accountId
to undefined
and use the setSiteId()
function to set a siteId
if you want to use an API key to call site-level APIs.
Name | Type | Description |
---|---|---|
accountId | string | ID of the Wix account to use when authenticating. |
Sets the site ID to use along with an API Key when authenticating.
Use a site ID for authentication when you need to call site-level APIs.
Set the siteId
to undefined
and use the setAccountId()
function to set an accountId
if you want to use an API key to call account-level APIs.
Name | Type | Description |
---|---|---|
siteId | string | ID of the Wix account to use when authenticating. |
The following code creates a client that can make requests to the coupons module using the API key strategy. The site ID is for providing site-level operations. To perform account-level operations, include the account ID instead of the site ID.