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
  • 0. Ask the Canvas team to enable the API
  • 1. Create an API key
  • 2. Configure the API call
  1. Building canvases

Events API

PreviousCanvas APINextEmbed Login API

Last updated 1 year ago

Canvas can receive events data pushed from your event tracker directly.

0. Ask the Canvas team to enable the API

Before proceeding, ask the Canvas team to enable the Events API for your team.

1. Create an API key

This step can only be done by a user with Owner permissions. Navigate to the page and scroll to the Events API section. Click the Create token button, then copy the generated key. This key is only generated one time and is not recoverable. You can create new keys.

Important: this key has permission to populate tables in your warehouse. Control access to the key as such.

2. Configure the API call

Configure your event stream to post the events data to events.canvasapp.com/v1/event. Here's code with an example payload:

POST /v1/event HTTP/1.1
Host: events.canvasapp.com
Content-Type: application/json
X-Auth-Token: [your api token]
Content-Length: 237

{
    "version"    : 1,
    "type"       : "event",
    "event"      : "Purchased an Item",
    "properties" : {
        "revenue"        : "39.95",
        "shippingMethod" : "2-day"
    },
    "timestamp" : "2012-12-02T00:30:08.276Z"
}

For Python:

import requests

url = "https://events.canvasapp.com/v1/event"

payload="{\n    \"version\"    : 1,\n    \"type\"       : \"event\",\n    \"event\"      : \"Purchased an Item\",\n    \"properties\" : {\n        \"revenue\"        : \"39.95\",\n        \"shippingMethod\" : \"2-day\"\n    },\n    \"timestamp\" : \"2012-12-02T00:30:08.276Z\"\n}"
headers = {
  'Content-Type': 'application/json',
  'X-Auth-Token': '[your_api_token]'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

For NodeJS:

var axios = require('axios');
var data = JSON.stringify({"version":1,"type":"event","event":"Purchased an Item","properties":{"revenue":"39.95","shippingMethod":"2-day"},"timestamp":"2012-12-02T00:30:08.276Z"});

var config = {
  method: 'post',
  url: 'https://events.canvasapp.com/v1/event',
  headers: { 
    'Content-Type': 'application/json', 
    'X-Auth-Token': '[your_api_token]'
  },
  data : data
};

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