> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chartbrew.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Chart Share Token

> Generate a signed JWT token for secure chart embedding with optional parameters and expiration

This endpoint generates a JWT token for embedding a chart with a SharePolicy. The token can include custom parameters, expiration dates, and URL parameter permissions.

## Parameters

<ParamField path="project_id" type="string" required>
  The ID of the project containing the chart
</ParamField>

<ParamField path="id" type="string" required>
  The ID of the chart
</ParamField>

## Body Parameters

<ParamField body="share_policy" type="object">
  Share policy configuration to update before generating token

  <Expandable title="Share Policy Object">
    <ParamField body="params" type="array">
      Array of parameters to include in the chart share policy

      <Expandable title="Parameter Object">
        <ParamField body="key" type="string">
          The parameter name/key
        </ParamField>

        <ParamField body="value" type="string">
          The parameter value
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="allow_params" type="boolean">
      Whether to allow URL parameters to override policy parameters for the chart
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="exp" type="string">
  Token expiration date and time in ISO 8601 format (e.g., "2024-12-31T23:59:59Z")
</ParamField>

## Response

<ResponseField name="token" type="string">
  The generated JWT access token for chart access
</ResponseField>

<ResponseField name="url" type="string">
  The complete embeddable URL with the access token included
</ResponseField>

## Example

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
    'https://api.chartbrew.com/project/123/chart/456/share/token' \
    -H 'Authorization: Bearer YOUR_API_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
      "share_policy": {
        "params": [
          {
            "key": "filter_date",
            "value": "2024-01"
          },
          {
            "key": "category",
            "value": "sales"
          }
        ],
        "allow_params": true
      },
      "exp": "2024-12-31T23:59:59Z"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.chartbrew.com/project/123/chart/456/share/token', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      share_policy: {
        params: [
          { key: 'filter_date', value: '2024-01' },
          { key: 'category', value: 'sales' }
        ],
        allow_params: true
      },
      exp: '2024-12-31T23:59:59Z'
    })
  });

  const data = await response.json();
  console.log(data.url); // Use this URL for embedding
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsidHlwZSI6IkNoYXJ0IiwiaWQiOjQ1Nn0sImlhdCI6MTY0MjQ0MDAwMCwiZXhwIjoxNzAzOTc2MDAwfQ.example_signature",
    "url": "https://app.chartbrew.com/chart/3b2a5538-6895-4856-8933-ef1e0c67a820/share?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsidHlwZSI6IkNoYXJ0IiwiaWQiOjQ1Nn0sImlhdCI6MTY0MjQ0MDAwMCwiZXhwIjoxNzAzOTc2MDAwfQ.example_signature"
  }
  ```
</ResponseExample>

## Usage Notes

* **Prerequisites**: A SharePolicy must exist for the chart before generating tokens. Use the "Create Chart Share Policy" endpoint first.
* **Token Expiration**: If no expiration is specified, the token will have a very long expiration (99999 days).
* **Parameters**: Parameters defined in the share policy will be passed as variables to the chart.
* **URL Parameters**: If `allow_params` is true, additional parameters can be passed via URL query parameters and will override policy parameters.
* **Embedding**: Use the returned URL in an iframe or directly link to it for chart embedding.
* **Security**: Always use HTTPS when sharing URLs containing access tokens.


## OpenAPI

````yaml POST /project/{project_id}/chart/{id}/share/token
openapi: 3.0.1
info:
  title: Chartbrew API reference
  description: The OpenAPI specification for Chartbrew
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.chartbrew.com
security:
  - bearerAuth: []
paths:
  /project/{project_id}/chart/{id}/share/token:
    post:
      description: Generate a share token for a chart embed
      parameters:
        - name: project_id
          in: path
          description: ID of the project
          required: true
          schema:
            type: string
        - name: id
          in: path
          description: ID of the chart
          required: true
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChartShareTokenRequest'
      responses:
        '200':
          description: Generated chart share token and URL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ShareTokenResponse'
        '400':
          description: Error response
        '401':
          description: Not authorized
        '403':
          description: Access denied
      security:
        - bearerAuth: []
components:
  schemas:
    ChartShareTokenRequest:
      type: object
      properties:
        share_policy:
          type: object
          properties:
            params:
              type: array
              items:
                type: object
                properties:
                  key:
                    type: string
                  value:
                    type: string
              description: Parameters to include in the chart share policy
            allow_params:
              type: boolean
              description: Whether to allow URL parameters for the chart
        exp:
          type: string
          format: date-time
          description: Token expiration date and time for the chart
    ShareTokenResponse:
      type: object
      properties:
        token:
          type: string
          description: The generated JWT access token
        url:
          type: string
          description: The complete URL with access token for sharing
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````