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.

Authorization

Request

This endpoint does not take any parameters

Response Object

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

Returns an empty object.

Status/Error Codes

Was this helpful?

Update a single property of a secret

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

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