You can access events stored in Zendesk with the Events API.

Each event is associated with a profile, which in turn is associated with a Zendesk user.

Event ↔ Profile ↔ Zendesk user

As a result, you can access events either by profile or by Zendesk user id. In either case, you can filter the results.

For information on storing the events, see Tracking events.

This article includes curl and Python examples. The Python examples use Python 3.6 or greater and the requests library.

Accessing events by profile identifier query

You can get events associated with person by using an identifier query to identify a profile associated with that person:

GET /api/v2/user_profiles/events?identifier={identifier_query}

The request path takes a required identifier parameter that specifies an identifier query. An identifier query selects a specific profile. Example:

coolbikes:rider:email:[email protected]

The first two items in the identifier query, coolbikes and rider, specify the target profile's source and type properties. The last two items, email and [email protected], specify an identifier in the profile for the person. For more information, see Using identifier queries with profiles.

You can include an optional filter[] path parameter in the request to get a subset of events. See Filtering events.

Example

Data

  • Identifier query:

    "coolbikes:rider:email:[email protected]"

  • Filter by start time:

    "2020-02-23"

  • Filter by end time:

    "2020-02-29"

curl request

curl -g "https://coolbikes.zendesk.com/api/v2/user_profiles/events?identifier=coolbikes:rider:email:[email protected]&filter[start_time]=2020-02-23&filter[end_time]=2020-02-29" \  -v -u devs@coolbikes.com/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

Python request

import requests

identifier_query = 'coolbikes:rider:email:[email protected]'start_time = '2020-02-23'end_time = '2020-02-29'
api_token = '6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv'
url = f'https://coolbikes.zendesk.com/api/v2/user_profiles/events'params = {    'identifier': identifier_query,    'filter[start_time]': start_time,    'filter[end_time]': end_time}credentials = '[email protected]/token', api_tokenresponse = requests.get(url, params=params, auth=credentials)if response.status_code != 200:    print(f'{response.status_code}: {response.text}')else:    print(response.json())

Response

Status 200 OK
{  "events":[    {      "id": "01E24ET0G1PHQ8QVNYRYM4QT8K",      "type": "bike_rental_booked",      "source": "coolbike",      "description": "Customer added item to shopping cart",      "created_at": "2020-02-28T18:13:28.175841347Z",      "received_at": "2020-02-28T18:13:28.175842838Z",      "properties": {        "booking_date": "2020-02-01",        "return_date": "2020-02-05"      }    }  ],  "links":[    {      "next": ""    }  ]}

Accessing events by profile id

You can get events associated with a person by using the id of a profile associated with that person:

GET /api/v2/user_profiles/{profile_id}/events

You can use the Profiles API to get a profile id.

You can include an optional filter[] path parameter in the request to get a subset of events. See Filtering events.

Example

Data

  • Profile id:

    "01E1G0NJSQPNPZRV096JXKXFAA"

  • Filter by start time:

    "2020-02-23"

  • Filter by end time:

    "2020-02-29"

curl request

curl -g "https://coolbikes.zendesk.com/api/v2/user_profiles/01E1G0NJSQPNPZRV096JXKXFAA/events?filter[start_time]=2020-02-23&filter[end_time]=2020-02-29" \  -v -u devs@coolbikes.com/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

Python request

import requests

profile_id = '01E1G0NJSQPNPZRV096JXKXFAA'start_time = '2020-02-23'end_time = '2020-02-29'
api_token = '6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv'
url = f'https://coolbikes.zendesk.com/api/v2/user_profiles/{profile_id}/events'params = {    'filter[start_time]': start_time,    'filter[end_time]': end_time}credentials = '[email protected]/token', api_tokenresponse = requests.get(url, params=params, auth=credentials)if response.status_code != 200:    print(f'{response.status_code}: {response.text}')else:    print(response.json())

Response

Status 200 OK
{  "events":[    {      "id": "01E24ET0G1PHQ8QVNYRYM4QT8K",      "type": "bike_rental_booked",      "source": "coolbike",      "description": "Customer added item to shopping cart",      "created_at": "2020-02-28T18:13:28.175841347Z",      "received_at": "2020-02-28T18:13:28.175842838Z",      "properties": {        "booking_date": "2020-02-01",        "return_date": "2020-02-05"      }    }  ],  "links":[    {      "next": ""    }  ]}

Accessing events by Zendesk user id

You can get events associated with a person by using a Zendesk user id to identify the person:

GET /api/v2/users/{user_id}/events

See Users in the Zendesk API docs.

You can include an optional filter[] path parameter in the request to get a subset of events. See Filtering events.

Example

Data

  • Zendesk user id:

    "85211553"

  • Filter by start time:

    "2020-02-23"

  • Filter by end time:

    "2020-02-29"

curl request

curl -g "https://coolbikes.zendesk.com/api/v2/users/85211553/events?filter[start_time]=2020-02-23&filter[end_time]=2020-02-29" \  -v -u devs@coolbikes.com/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

Python request

import json
import requests

user_id = '85211553'start_time = '2020-02-23'end_time = '2020-02-29'
api_token = '6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv'
url = f'https://coolbikes.zendesk.com/api/v2/users/{user_id}/events'params = {    'filter[start_time]': start_time,    'filter[end_time]': end_time}credentials = '[email protected]/token', api_tokenresponse = requests.get(url, params=params, auth=credentials)if response.status_code != 200:    print(f'{response.status_code}: {response.text}')else:    print(response.json())

Response

Status 200 OK
{  "events":[    {      "id": "01E24ET0G1PHQ8QVNYRYM4QT8K",      "type": "bike_rental_booked",      "source": "coolbike",      "description": "Customer added item to shopping cart",      "created_at": "2020-02-28T18:13:28.175841347Z",      "received_at": "2020-02-28T18:13:28.175842838Z",      "properties": {        "booking_date": "2020-02-01",        "return_date": "2020-02-05"      }    }  ],  "links":[    {      "next": ""    }  ]}