getSecret( )


Gets a secret by name.

The getSecret() function returns a Promise that resolves to the value of the secret that was stored in the Secrets Manager with the given name.

Note: To prevent malicious users from accessing the value of your secret, don't return the value of the secret to client side. Only use the secret's value in the backend.

Method Declaration
Copy
function getSecret(name: string): Promise<string>;
Method Parameters
namestringRequired

The name of the secret to get the value of.

Returns
Return Type:Promise<string>
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import wixSecretsBackend from "wix-secrets-backend"; import { getJSON } from "wix-fetch"; export const getSomeJSON = webMethod(Permissions.Anyone, () => { return wixSecretsBackend .getSecret("myApiKeyName") .then((secret) => { return getJSON(`https://someapi.com/api/someendpoint?apiKey=${secret}`); }) .catch((error) => { console.error(error); }); }); export const getFirstSecretValue = webMethod(Permissions.Anyone, () => { return wixSecretsBackend .listSecretInfo() .then((secrets) => { return wixSecretsBackend.getSecret(secrets[0].name); }) .catch((error) => { console.error(error); }); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?