> 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`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# GenerateSiteMediaToken

# Package: richContent

# Namespace: RicosDocument

# Method link: https://dev.wix.com/docs/api-reference/assets/rich-content/ricos-documents/generate-site-media-token.md

## Permission Scopes:
Manage Ricos Document: SCOPE.DC-RICOS.MANAGE-DOCUMENTS

## Introduction

Generates a site media token that lets a Ricos editor open Wix media tools, such as Image Studio, for the current Wix user.

Pass the token as `siteToken` when you open Image Studio from the Ricos image plugin. The token identifies
the site and the Wix user, and is valid only in a browser where that user is logged in to Wix.
It expires after 14 days, so you can reuse it for the editor session.

Only Wix users can call this method. Calls by site members, site visitors, or anonymous callers
fail with a permission error. Wix app calls without a Wix user fail with a `WIX_USER_REQUIRED` error.

---

## REST API

### Schema

```
 Method: generateSiteMediaToken
 Description: Generates a site media token that lets a Ricos editor open Wix media tools, such as Image Studio, for the current Wix user.  Pass the token as `siteToken` when you open Image Studio from the Ricos image plugin. The token identifies the site and the Wix user, and is valid only in a browser where that user is logged in to Wix. It expires after 14 days, so you can reuse it for the editor session.  Only Wix users can call this method. Calls by site members, site visitors, or anonymous callers fail with a permission error. Wix app calls without a Wix user fail with a `WIX_USER_REQUIRED` error.
 URL: https://www.wixapis.com/ricos/v1/ricos-document/generate-site-media-token
 Method: POST
 Return type: GenerateSiteMediaTokenResponse
  - name: token | type: string | description: Site media token to pass to the Wix media tool. Expires after 14 days. Treat the token as a secret. Don't log it or share it.  | validation: maxLength 5000

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: WIX_USER_REQUIRED | Description: The caller isn't a Wix user.


```

### Examples

### Generate a site media token
```curl
curl -X POST \
'https://www.wixapis.com/ricos/v1/ricos-document/generate-site-media-token' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.richContent.ricosDocuments.generateSiteMediaToken()
 Description: Generates a site media token that lets a Ricos editor open Wix media tools, such as Image Studio, for the current Wix user.  Pass the token as `siteToken` when you open Image Studio from the Ricos image plugin. The token identifies the site and the Wix user, and is valid only in a browser where that user is logged in to Wix. It expires after 14 days, so you can reuse it for the editor session.  Only Wix users can call this method. Calls by site members, site visitors, or anonymous callers fail with a permission error. Wix app calls without a Wix user fail with a `WIX_USER_REQUIRED` error.
 Return type: PROMISE<GenerateSiteMediaTokenResponse>
  - name: token | type: string | description: Site media token to pass to the Wix media tool. Expires after 14 days. Treat the token as a secret. Don't log it or share it.  | validation: maxLength 5000

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: WIX_USER_REQUIRED | Description: The caller isn't a Wix user.


```

### Examples

### Generate a site media token
```javascript
import { ricosDocuments } from "@wix/rich-content";

async function generateSiteMediaToken() {
  const response = await ricosDocuments.generateSiteMediaToken();
}

/* Promise resolves to:
 * {
 *   "token": "JWS.<SITE_MEDIA_TOKEN>"
 * }
 */

```

### generateSiteMediaToken (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { ricosDocuments } from '@wix/rich-content';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { ricosDocuments },
  // Include the auth strategy and host as relevant
});


async function generateSiteMediaToken() {
  const response = await myWixClient.ricosDocuments.generateSiteMediaToken();
};
```

---