Search.../

updateSecret( )

Updates the specified fields of an existing secret by ID.

Description

The updateSecret() function returns a Promise that resolves when the secret is successfully updated. You can update one or more secret properties. Only the properties passed in the Secret object will be updated. All other properties will remain the same. You can retrieve the id parameter from the listSecretInfo() function. The id is not the same as the secret name used by the getSecret() function.

Notes:

  • Changing a secret's name or value will break all code using the secret.

  • You cannot rename the secret with a name that is already in use.

  • Do not leave private keys in your code! Leaving them in is a security risk. Either delete the keys from the code after running updateSecret(), or pass the parameters in using the Functional Testing tool.

Syntax

function updateSecret(id: string, secret: SecretUpdateInfo): Promise<void>

updateSecret Parameters

NAME
TYPE
DESCRIPTION
id
string

The ID of the secret to update.

secret
SecretUpdateInfo

The information to update the secret with.

Returns

Fulfilled - When the secret is updated. Rejected - Error message.

Return Type:

Promise<void>

Was this helpful?

Update a single property of a secret

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixSecretsBackend from 'wix-secrets-backend';
3
4export const updateName = webMethod(Permissions.Anyone, () => {
5 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";
6 const secret = {
7 name: "my_new_secret_name"
8 };
9
10 return wixSecretsBackend.updateSecret(id, secret)
11 .then(() => {
12 console.log("Secret name updated");
13 })
14 .catch((error) => {
15 console.error(error);
16 })
17});
Update multiple properties of a secret

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixSecretsBackend from 'wix-secrets-backend';
3
4export const updateMultipleProperties = webMethod(Permissions.Anyone, () => {
5 const id = "b741766c-eead-46fe-8e7f-fd01ff3d6e21";
6 const secret = {
7 name: "my_new_secret_name",
8 description: "New description",
9 value: "new.key.44aSQCljxL9FLvTVA.9dKbpwueYoQ8isyQhvun19pOT9gHEdgxam39LJ0Ts70"
10 };
11
12 return wixSecretsBackend.updateSecret(id, secret)
13 .then(() => {
14 console.log("All secret fields updated");
15 })
16 .catch((error) => {
17 console.error(error);
18 });
19});