Setup

To use the Secrets API, install the @wix/secrets package using npm or Yarn:

Copy
1
npm install @wix/secrets

or

Copy
1
yarn add @wix/secrets

Then import { secrets } from @wix/secrets:

Copy
1
import { secrets } from '@wix/secrets'
Was this helpful?
Yes
No

createSecret( )

Creates a new secret.

The createSecret() function returns a Promise that resolves secret ID when the secret is created.

Notes:

  • The secret's name cannot start with 'wix' or be identical to an existing secret's name.
  • Don't leave private keys in your code. Leaving them in your code is a security risk. Make sure to delete the keys from the code after running createSecret().

Permission Scopes

For app development, you must have one of the following permission scopes:
Manage Secrets
Learn more about permission scopes.
Copy
function createSecret(secret: Secret): Promise<string>
Method Parameters
secretSecretRequired

Fields of a new secret.

Returns
Return Type:Promise<string>
Was this helpful?
Yes
No

deleteSecret( )

Deletes an existing secret by ID.

The deleteSecret() function returns a Promise that resolves when the secret is deleted. You can retrieve the secret _id using the listSecretInfo() function.

Note: Deleting a secret is irreversible and will break all code using the secret.

Permission Scopes

For app development, you must have one of the following permission scopes:
Manage Secrets
Learn more about permission scopes.
Copy
function deleteSecret(_id: string): Promise<void>
Method Parameters
_idstringRequired

The unique ID of the secret to be deleted.

Was this helpful?
Yes
No

getSecretValue( )

Retrieves the secret value specified by the secret name.

The getSecretValue() function returns a Promise that resolves to the value of the secret with the specified given name.

Note: Only use a secret's value in the backend code. Returning the secret value in the frontend is a security risk.

Permission Scopes

For app development, you must have one of the following permission scopes:
Manage Secrets
Learn more about permission scopes.
Copy
function getSecretValue(name: string): Promise<GetSecretValueResponse>
Method Parameters
namestringRequired

The name of the secret to get the value of.

Returns
Return Type:Promise<GetSecretValueResponse>
Was this helpful?
Yes
No

listSecretInfo( )

Retrieves a list of objects containing information about all secrets.

The listSecretInfo() function returns a Promise that resolves to a list containing information about all secrets stored on your site.

Note:

  • The secret's value does not get returned for security reasons. To retrieve a secret's value, use the getSecretValue() function.

Permission Scopes

For app development, you must have one of the following permission scopes:
Manage Secrets
Learn more about permission scopes.
Copy
function listSecretInfo(): Promise<ListSecretInfoResponse>
Request
This method does not take any parameters
Returns
Return Type:Promise<ListSecretInfoResponse>
Was this helpful?
Yes
No

updateSecret( )

Updates the specified fields of an existing secret by ID.

The updateSecret() function returns a Promise that resolves when the secret is successfully updated. You can update one or more fields. Only fields passed in the secret object will be updated. All other properties will remain unchanged.

You can retrieve the _id parameter from the listSecretInfo() function. The secret _id is different from the secret name used by the getSecretValue() function.

Notes:

  • Changing a secret's name or value will break all code using the secret.
  • You can't rename the secret with a name of an existing secret.
  • Don't leave private keys in your code! Leaving them in is a security risk. Make sure to delete the keys from the code after running updateSecret().

Permission Scopes

For app development, you must have one of the following permission scopes:
Manage Secrets
Learn more about permission scopes.
Copy
function updateSecret(_id: string, secret: Secret): Promise<void>
Method Parameters
_idstringRequired

The unique ID of the secret to be updated.


secretSecretRequired

The secret fields to update.

Was this helpful?
Yes
No