Canvas Docs
  • GETTING STARTED
    • Our docs have moved
    • Connect your data
      • App and database connectors
      • Snowflake
      • BigQuery
      • Redshift
      • Postgres
        • Use an SSH tunnel
      • Static IP Addresses
      • dbt
        • dbt Cloud
        • dbt via GitHub
    • Create your first canvas
    • Onboarding your team
  • Building canvases
    • Import data
    • Formulas
    • SQL
    • Joins
    • Pivot tables
    • Charts
    • Filters
      • Date filters
      • Text search filters
      • Multi-select filters
    • Canvas API
    • Events API
    • Embed Login API
  • Embeds
    • Public Embeds
    • Scopes
    • Walkthrough
    • PowerPoint embeds
  • Managing users
    • Assigning permissions
  • Security
    • Data security
    • Bug bounty program
    • Privacy policy
    • Terms of service
Powered by GitBook
On this page
  • 1. Create an API key
  • 2. Get Canvas and Element IDs
  • 3. Write the API Call
  1. Building canvases

Canvas API

PreviousMulti-select filtersNextEvents API

Last updated 1 year ago

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 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:

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:

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);
});
Settings