Events API

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

Last updated