> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: getSecretValue(name: string)

# Method package: wixSecretsBackendV2

# Method menu location: wixSecretsBackendV2 --> secrets --> getSecretValue

# Method Link: https://dev.wix.com/docs/velo/apis/wix-secrets-backend-v2/secrets/get-secret-value.md

# Method Description:

Retrieves a secret value by name.

<blockquote class="caution">
__Caution:__
Only use a secret's value in the backend code. Returning the secret value in the frontend is a security risk.
</blockquote>



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Get a secret and use it to fetch a JSON from a 3rd-party service (dashboard page code)

```javascript
import { secrets } from 'wix-secrets-backend.v2';
import {getJSON} from 'wix-fetch';
import { elevate } from 'wix-auth';

const elevatedGetSecretValue = elevate(secrets.getSecretValue);
const elevatedListSecretInfo = elevate(secrets.listSecretInfo);

export function getSomeJSON() {
  return elevatedGetSecretValue('myApiKeyName')
    .then((secret) => {
      return getJSON(`https://someapi.com/api/someendpoint?apiKey=${secret}`);
    })
    .catch((error) => {
      console.error(error);
    });
}

export function getFirstSecretValue() {
  return elevatedListSecretInfo()
    .then((secrets) => {
      return elevatedGetSecretValue(secrets[0].name);
    })
    .catch((error) => {
      console.error(error);
    });
}

```

## Get a secret and use it to fetch a JSON from a 3rd-party service (export from backend code)

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { secrets } from 'wix-secrets-backend.v2';
import { getJSON } from 'wix-fetch';
import { elevate } from 'wix-auth';

const elevatedGetSecretValue = elevate(secrets.getSecretValue);
const elevatedListSecretInfo = elevate(secrets.listSecretInfo);

export const getSomeJSON = webMethod(Permissions.Anyone, () => {
  return elevatedGetSecretValue('myApiKeyName')
    .then((secret) => {
      return getJSON(`https://someapi.com/api/someendpoint?apiKey=${secret}`);
    })
    .catch((error) => {
      console.error(error);
    });
});

export const getFirstSecretValue = webMethod(Permissions.Anyone, () => {
  return elevatedListSecretInfo()
    .then((secrets) => {
      return elevatedGetSecretValue(secrets[0].name);
    })
    .catch((error) => {
      console.error(error);
    });
});

```

## Retrieve a name and get a secret's value 

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { secrets } from 'wix-secrets-backend.v2';
import { elevate } from 'wix-auth';

const elevatedGetSecretValue = elevate(secrets.getSecretValue);
const elevatedListSecretInfo = elevate(secrets.listSecretInfo);

export const getFirstSecretValue = webMethod(Permissions.Anyone, () => {
  return elevatedListSecretInfo()
    .then((secrets) => {
      return elevatedGetSecretValue(secrets[0].name);
    })
    .catch((error) => {
      console.error(error);
    });
});

/*
 * Returns a Promise that resolves to:
 *
 * "Fm8OfflH6bJOwWjenqAtLurLbkiMNvmhQHZV+118"
 */

```

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

```javascript
/************************************
 * Backend code - getWeather.web.js *
 ************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { secrets } from 'wix-secrets-backend.v2';
import { getJSON } from 'wix-fetch';
import { elevate } from 'wix-auth';

const elevatedGetSecretValue = elevate(secrets.getSecretValue);

export const getWeatherJson = webMethod(Permissions.Anyone, async () => {
  const secret = await elevatedGetSecretValue('openWeatherApiKey');
  return getJSON(`https://api.openweathermap.org/data/2.5/weather?q=London&units=metric&APPID=${secret}`);
});

/********************
 * Frontend code *
 ********************/

import { getWeatherJson } from 'backend/getWeather.web';

export async function getWeather_click(event) {
  let json = await getWeatherJson();
  $w('#weather').text = json.weather[0].description; // "mist"
  $w('#temp').text = json.main.temp; // 9.4 (degrees Celsius)
}
```

## Get an API key and use it to send an email with the SendGrid npm interface 

```javascript
/************************************
 * Backend code - sendEmail.web.js *
 ************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { secrets } from 'wix-secrets-backend.v2';
import sendGridMail from '@sendgrid/mail';
import { elevate } from 'wix-auth';

const elevatedGetSecretValue = elevate(secrets.getSecretValue);

export const sendEmail = webMethod(Permissions.Anyone, async (recipient, sender, subject, body) => {
  const secret = await elevatedGetSecretValue('SendGridApiKey');
  sendGridMail.setApiKey(secret);
  const message = {
    'to': recipient,
    'from': sender,
    'subject': subject,
    'text': body
  };
  sendGridMail.send(message);
});

/********************
 * Frontend code *
 ********************/

import { sendEmail } from 'backend/sendEmail.web';

export function sendEmailButton_click(event) {
  sendEmail(
    $w('#toEmail').value,
    $w('#fromEmail').value,
    $w('#subject').value,
    $w('#emailContent').value
  )
    .then(() => {
      console.log('Email sent');
    })
    .catch((error) => {
      console.error(error);
    })
}
```

---