Export data
You can export data from specific section (People/Deals/etc.) or campaign logs (Email deliveries/clicks or SMS deliveries) based on segment (for sections) as well as based on date of campaign sending or user's click/opening/unsubscription.
| Attributes | Type | Required | Description |
|---|---|---|---|
| segment | integer | yes / no | A unique identifier for the segment of People/Deals/etc. |
| date_from | date (Y-m-d) | no | A date from which the data will be returned (format: Y-m-d, e.g.,
2024-01-15). |
| date_to | date (Y-m-d) | no | A date to which the data will be returned (format: Y-m-d,
e.g.,2024-01-31). |
| filter_by | array | no | Array of email action types to filter by, based on the
|
| event_id | integer | yes / no | ID of the specific event. |
| deal_id | integer | no | ID of the specific deal. |
| type | string | yes | Type of the exported data.
|
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/exports/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"type": "people",
"segment": 43
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/exports/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
type: "people",
segment: 43,
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/exports/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"type" => "people",
"segment" => 43,
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/exports/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"type": "people",
"segment": 43,
},
)
print(response.json())
Response examples
- 200 OK
- 400 Bad Request
{
"filename": "d1d69214-d07f-418f-bd85-27c49fd3398f.csv"
}
{
"error": "Type not-a-type is not valid. Valid options are sms_delivery_logs, email_delivery_logs, email_clicks, people, activities, companies, deals, products, tickets, people_timelines, deals_stage_changes, events"
}
A 400 for a missing or unknown type has an error text. Other problems name the field:
| Message | When |
|---|---|
error: Type None is not valid. Valid options are … | The body has no type, or type isn't one of the values listed. |
segment: This field is required. | A section export (people, tickets and the others) without segment. |
segment: Segment does not exist. | No segment has that ID. |
event_id: This field is required. / Id of existing event should be passed | An events export without event_id, or with an ID no event has. |
filter_by: Expected a list of items but got type "str". | filter_by isn't a list, even for one action. |
filter_by: This data type does not contain all of passed filter columns. | filter_by has an action that isn't sent_at, opened_at, clicked_at or unsubscribed_at. |
date_from: Date has wrong format. Use one of these formats instead: YYYY-MM-DD. | A date isn't YYYY-MM-DD. |
A date_from later than date_to isn't an error: the export is created. The file is built in the background; Download exported data answers 423 until it's ready. How long that takes depends on the size of the export: seconds for a small segment, much longer for a large one. Get all exported files shows the export's status and finished_at.
Response fields
Fields returned in the 200 OK response body.
- filename
- Name of the export file. Use it to download the file.
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.
Email logs export example
- cURL
- JavaScript
- PHP
- Python
curl -X POST
"https://<your_app_subdomain>.user.com/api/public/exports/"
-H 'authorization: Token <your_64_char_api_key>'
-H 'content-type: application/json'
-H "Accept: */*; version=2"
-d '{
"type": "email_delivery_logs",
"date_from": "2024-01-01",
"date_to": "2024-01-31",
"filter_by": ["sent_at", "opened_at"]
}'
var data = JSON.stringify({
type: "email_delivery_logs",
date_from: "2024-01-01",
date_to: "2024-01-31",
filter_by: ["sent_at", "opened_at"],
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/exports/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("accept", "*/*; version=2");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/exports/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n\t\"type\": \"email_delivery_logs\",\n\t\"date_from\": \"2024-01-01\",\n\t\"date_to\": \"2024-01-31\",\n\t\"filter_by\": [\"sent_at\", \"opened_at\"]\n}",
CURLOPT_HTTPHEADER => array(
"Accept: */*; version=2",
"authorization: Token <your_64_char_api_key>",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
url = "https://<your_app_subdomain>.user.com/api/public/exports/"
payload = "{\n\t\"type\": \"email_delivery_logs\",\n\t\"date_from\": \"2024-01-01\",\n\t\"date_to\": \"2024-01-31\",\n\t\"filter_by\": [\"sent_at\", \"opened_at\"]\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'Accept': "*/*; version=2",
'content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)