# Publishing API

## Overview

You can publish your charts to ChartSQL Cloud to share and create dashboards. ChartSQL Studio provides all of the capabilities for publishing, but you may also use the API if you are doing your own automations.

This document describes the API calls for publishing charts to ChartSQL.com

## Publisher Authentication

In order to publish charts, you need to be an approved `Publisher` for a `Package`. You will need a ChartSQL Cloud account.

If you are not the creator/owner of a Package on ChartSQL Cloud, the Package owner needs to give your user Publisher access.

### Publishing Key

From your ChartSQL Cloud account settings, go to Packages. From there you can create a new Publisher Key. A Publisher Key is a unique password that gives you API access to publish to the Package. Do not share your Publishing Key with anyone else, it is like a password, and it is tied to your ChartSQL Cloud account.

Publishing Keys are securely stored and cannot be recovered by ChartSQL support. If you forget or lose your key, you will need to create another.

#### Publishing Key Format

Typically you will not need to do this encoding yourself. The Publishing Key format is a base64 encoded string of your Publisher Key Id and its password. When you created your publishing key in the ChartSQL Cloud UI, you will have received your base64 encoded string.

toBase64("{{publisherKeyId}}:{{password}}")

The publishing key allows ChartSQL Cloud to identify the account by `publisherKeyId` and verify access by comparing the salted and hashed value of the `password`.

## Base URL

<http://api.chartsql.com/PublisherKey/\\{{publishingKey\\}}/>

## Endpoints

### Publish Chart

POST <http://api.chartsql.com/PublisherKey/\\{{publishingKey\\}}/publishDashChart.json>

#### Fields

| Name     | Required | Description                             |
| -------- | -------- | --------------------------------------- |
| sql      | yes      | The SQL content of the chart            |
| fileName | yes      | The local file system name of the chart |

### Update Chart

POST <http://api.chartsql.com/PublisherKey/\\{{publishingKey\\}}/updateDashChart.json>

#### Fields

| Name     | Required | Description                                                        |
| -------- | -------- | ------------------------------------------------------------------ |
| sql      | yes      | The SQL content of the chart                                       |
| fileName | yes      | The local file system name of the chart                            |
| dashId   | yes      | The @dash-id that uniquely identifies the already published chart. |

### Verify/Stats

POST <http://api.chartsql.com/PublisherKey/\\{{publishingKey\\}}/stats.json>

You use the /stats endpoint to verify access to the PublisherKey. If the publishing key fails, an error will be returned.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chartsql.com/reference/publishing-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
