# Canvas API

You can use the Canvas API to download the tables that you've built in Canvas programatically.

### 1. Create an API key

This step can only be done by a user with Owner permissions. Navigate to the [Settings](https://canvasapp.com/team_settings) page and click the `Create Key` button, then copy the generated key. This key is only generated one time and is not recoverable; however, you can create new keys.

**Important**: this key has permission to view the data associated with all tables on all canvases on the team. Control access to the key as such.

### 2. Get Canvas and Element IDs

Navigate to the canvas and table that you want to download. Open the three-dot menu on the table, and select `Share Element` (or click `⌥ + Shift + S`). This will copy a URL containing the canvas and element ID to your clipboard in the format `https://canvasapp.com/canvas/[canvasId]/element/[elementId]/new-canvas`\
Note down the IDs for the next step.

### 3. Write the API Call

In the language of your choice, call the API. The plain HTTP spec is:

```
POST /data/table HTTP/1.1
Host: api.canvasapp.com
x-api-key: [your_api_key]
Content-Type: application/json
{
    "canvasId": "[your_canvas_id]",
    "elementId": "[your_element_id]"
}
```

For Python:

```python
import requests
url = "https://canvasapp.com/api/data/table"
payload="{ \"canvasId\": \"[your_canvas_id]\", \"elementId\": \"[your_element_id]\" }"
headers = {
  'x-api-key': '[your_api_key]',
  'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
```

For NodeJS:

```javascript
var axios = require('axios');
var data = JSON.stringify({"canvasId":"[your_canvas_id]","elementId":"[your_element_id]"});

var config = {
  method: 'post',
  url: 'https://canvasapp.com/api/data/table',
  headers: { 
    'x-api-key': '[your_api_key]', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```


---

# 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://canvasapp.gitbook.io/docs/building-canvases/canvas-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.
