# 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](https://canvasapp.com/team_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.

<figure><img src="/files/PUOv71YVTOfOZ4shbuFd" alt=""><figcaption></figcaption></figure>

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

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

```javascript
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);
});
```


---

# 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/events-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.
