ApiKeyStrategy

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.

ApiKeyStrategy()

Creates an authentication strategy object that uses an API key.

Syntax

Copy

Parameters

NameTypeDescription
apiKeystringThe API key to use for authentication.
accountIdstringOptional. The account ID to use for authentication when calling account-level APIs.
siteIdstringOptional. 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.

Returns

ApiKeyStrategy

Functions

setAccountId()

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.

Syntax

Copy

Parameters

NameTypeDescription
accountIdstringID of the Wix account to use when authenticating.

setSiteId()

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.

Syntax

Copy

Parameters

NameTypeDescription
siteIdstringID of the Wix account to use when authenticating.

Example

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.

Copy
Did this help?