Skip to main content
Backfill your events

This article describes how you can backfill your old event data using the June API.

Updated over a year ago

Currently, June can only generate reports on event data that it receives starting on the day you connect Segment or implement our SDK. If you have access to old event data, you can easily send it to June by using our API:

  • Sending a request to identify a user

  • Sending a request to track an event for a user

Here are some sample payloads and code that you can check out:

Identify a user

Field

Type

Description

type

required, value: identify

String

The type of payload

userId

optional if anonymousId is set instead

String

A unique id for the user in your database

traits

optional

Object

A dictionary of traits for a user, like email or name

Node.Js

const axios = require('axios');

// Identify object
identify = {
type: "identify",
userId: "1",
traits: {
name: "Elon Musk",
email: "[email protected]",
plan: "pro",
logins: 1
}
}

// JSON format expected
const options = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Basic <YOUR API KEY>',
},
};

const url = 'https://api.june.so/api/identify';

// Send event to June
axios.post(url, identify, options);

Python

identify_payload = {
"type": "identify",
"userId": "1",
"traits": {
"name": "Elon Musk",
"email": "[email protected]",
"plan": "pro",
"logins": 1
}
}

identify_url = "https://api.june.so/api/identify"
api_key = "secret_api_key" # from the June settings page

response = requests.post(
identify_url,
json=identify_payload,
headers={'Authorization': f'Basic {api_key}'}
)

assert response.status_code == 200


Identify a company

Field

Type

Description

type

required, value: group

String

The type of payload

groupId

required

String

A unique id for the company in your database

userId

required

String

A unique id for the user in your database

traits

optional

Object

A dictionary of traits for a user, like email or name

Node.Js

const axios = require('axios');

// Group object
group = {
type: "group",
groupId: "A",
userId: "1",
traits: {
name: "SpaceX"
}
}

// JSON format expected
const options = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Basic <YOUR API KEY>',
},
};

const url = 'https://api.june.so/api/group';

// Send event to June
axios.post(url, group, options);

Python

group_payload = {
"type": "group",
"groupId": "A",
"userId": "1",
"traits": {
"name": "SpaceX"
}
}

group_url = "https://api.june.so/api/group"
api_key = "secret_api_key" # from the June settings page

response = requests.post(
group_url,
json=group_payload,
headers={'Authorization': f'Basic {api_key}'}
)

assert response.status_code == 200

Track an event for a user

Field

Type

Description

type

required, value: track

String

The type of payload

event

required

String

The name of the event that a user performed

userId

optional if anonymousId is set instead

String

A unique id for the user in your database

timestamp

required, ISO format with timezone set to UTC

String

The time at which the user performed the event

email

optional if anonymousId is set

String

The email for the user who performed this event

properties

optional

Object

A dictionary of properties for the event, like revenue

context

optional

Object

Additional context for the event

Node.Js

const axios = require('axios');

// Event object
const event = {
type: 'track',
event: 'Dashboard Loaded',
userId: '1',
timestamp: '2021-02-24T01:19:38.931Z',
email: '[email protected]',
};

// JSON format expected
const options = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Basic <YOUR API KEY>',
},
};

const url = 'https://api.june.so/api/track';

// Send event to June
axios.post(url, event, options);

Python

track_payload = {
"type": "track",
"event": "Registered",
"userId": "1",
"timestamp": "2021-02-24T01:19:38.931Z",
"email": "[email protected]",
"properties": {
"plan": "pro"
}
}

track_url = "https://api.june.so/api/track"
api_key = "secret_api_key" # from the June settings page

response = requests.post(
track_url,
json=track_payload,
headers={'Authorization': f'Basic {api_key}'}
)

assert response.status_code == 200


Did this answer your question?