About the Secrets API

The Secrets API contains functionality for managing secrets on a site. Secrets managed by this API are available in the Secrets Manager section of a site's dashboard. You can securely store API keys and other secrets on a site. Each secret's value is encrypted and assigned a name of your choice and an ID. You can then use the name or ID to refer to the secret in your backend code rather than hardcoding its value.

Learn more about the Secrets Manager.

With the Secrets API, you can safely:

  • Create a secret.
  • Delete a secret.
  • Update a secret.
  • Retrieve a secret value.
  • Retrieve other information about your secrets, such as their names and descriptions.

Before you begin

It's important to note the following:

  • Before you can create or manage secrets with the Secrets API on a site, the site must have the Wix Members Area app installed. The Members Area isn't required to retrieve secrets with the Get Secret Value method.
  • Deleting a secret, or modifying a secret's name or value, breaks all code using the secret.
  • You can't create or rename a secret with a name that's already in use.

Security considerations

  • If you currently use private keys in your code, we recommend removing them.
  • To prevent malicious users from accessing the values of your secrets, use them only in backend code. Avoid using secret values in frontend code.
  • When developing websites or using Blocks, don't call List Secret Info in a .web.js file with anonymous permissions. This is a serious security risk which exposes your secrets to potential leaks. To prevent this, call List Secret Info in a separate .js file to block frontend access. If you must call List Secret Info in a .web.js file, make sure the exported function has permissions set to Admin.

Use Cases

  • Get an API key and use it to fetch information from a weather service.

Terminology

  • Secret: Secrets are values that you don’t want to be publicly accessible, such as login credentials or API keys.
  • API key: An API key is a unique code used to authenticate a user or program when making a call to an API.
Did this help?

Secrets: Sample Use Cases and Flows

This article presents possible use cases and corresponding sample flows that your app can support. It provides a useful starting point as you plan your app's implementation.

Get an API key and use it to fetch information from a weather service

This use case demonstrates how you can store an API key from a weather service (for example, https://openweathermap.org/), and then use it to fetch the weather information to display on a site.

To get the weather data:

  1. Call Create Secret to store your API key you received after signing up on the OpenWeather site.

  2. Call Get Secret Value, assign the returned value to a variable, and make an OpenWeather API call. For example:

    Copy
  3. Extract the required values from the returned JSON object and display them on a site.

Did this help?

Secret Object


Properties
idstringRead-onlyformat GUID

Secret ID.


namestringmaxLength 50

A unique, human-friendly name for the secret. Use it to retrieve the secret value easily with the Get Secret Value endpoint.

Note: You can use alphanumeric characters and the following special characters: _+=-@#$. Spaces are not supported.


descriptionstringmaxLength 200

An optional text describing the secret's purpose or any other notes about it.


valuestringminLength 1maxLength 3500

The encrypted confidential value.


createdDatestringRead-onlyformat date-time

Date and time when the secret was created.


updatedDatestringRead-onlyformat date-time

Date and time when the secret was updated.

Secret
JSON
Did this help?