Export users CSV
curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/users/csv_export \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"segment_name": "<string>",
"include_unsubscribed": true
}
'const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({
segment_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
segment_name: '<string>',
include_unsubscribed: true
})
};
fetch('https://api.onesignal.com/apps/{app_id}/users/csv_export', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.onesignal.com/apps/{app_id}/users/csv_export"
payload = {
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"segment_name": "<string>",
"include_unsubscribed": True
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.onesignal.com/apps/{app_id}/users/csv_export",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'segment_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'segment_name' => '<string>',
'include_unsubscribed' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.onesignal.com/apps/{app_id}/users/csv_export"
payload := strings.NewReader("{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.onesignal.com/apps/{app_id}/users/csv_export")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}"
response = http.request(request)
puts response.read_bodyHttpResponse<String> response = Unirest.post("https://api.onesignal.com/apps/{app_id}/users/csv_export")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}")
.asString();using RestSharp;
var options = new RestClientOptions("https://api.onesignal.com/apps/{app_id}/users/csv_export");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "<authorization>");
request.AddJsonBody("{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
false{
"csv_file_url": "https://onesignal.com/csv_exports/YOUR_APP_ID/onesignal_users_0f1e2d3c4b5a69788796a5b4c3d2e1f0.csv.gz"
}{
"success": false,
"errors": [
"'segment_id' The provided segment does not exist"
]
}{
"errors": [
"Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
]
}{
"success": false,
"errors": [
"Exports have been disabled for this app due to exceeding a limit. Please see https://documentation.onesignal.com/docs/disabled-apps for more information and instructions to re-enable your app."
]
}{
"success": false,
"errors": [
"Only one export may run at a time."
]
}Export users CSV
Request a GZip-compressed CSV with one row per user, including External ID, Tags, language, timezone, location, and session times. For apps with user-based segmentation. In beta. Filter by segment ID or name.
POST
/
apps
/
{app_id}
/
users
/
csv_export
Export users CSV
curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/users/csv_export \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"segment_name": "<string>",
"include_unsubscribed": true
}
'const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({
segment_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
segment_name: '<string>',
include_unsubscribed: true
})
};
fetch('https://api.onesignal.com/apps/{app_id}/users/csv_export', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.onesignal.com/apps/{app_id}/users/csv_export"
payload = {
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"segment_name": "<string>",
"include_unsubscribed": True
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.onesignal.com/apps/{app_id}/users/csv_export",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'segment_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'segment_name' => '<string>',
'include_unsubscribed' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.onesignal.com/apps/{app_id}/users/csv_export"
payload := strings.NewReader("{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.onesignal.com/apps/{app_id}/users/csv_export")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}"
response = http.request(request)
puts response.read_bodyHttpResponse<String> response = Unirest.post("https://api.onesignal.com/apps/{app_id}/users/csv_export")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}")
.asString();using RestSharp;
var options = new RestClientOptions("https://api.onesignal.com/apps/{app_id}/users/csv_export");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "<authorization>");
request.AddJsonBody("{\n \"segment_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"segment_name\": \"<string>\",\n \"include_unsubscribed\": true\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
false{
"csv_file_url": "https://onesignal.com/csv_exports/YOUR_APP_ID/onesignal_users_0f1e2d3c4b5a69788796a5b4c3d2e1f0.csv.gz"
}{
"success": false,
"errors": [
"'segment_id' The provided segment does not exist"
]
}{
"errors": [
"Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
]
}{
"success": false,
"errors": [
"Exports have been disabled for this app due to exceeding a limit. Please see https://documentation.onesignal.com/docs/disabled-apps for more information and instructions to re-enable your app."
]
}{
"success": false,
"errors": [
"Only one export may run at a time."
]
}Exporting users requires user-based segmentation, which is in beta. Functionality may change before general availability. To request access, contact support@onesignal.com.
Overview
Use this endpoint to export your Users as a GZip-compressed CSV file, with one row per user. The response returns a URL where the file is uploaded when the export finishes. To export one row per Subscription instead, use Export subscriptions CSV.How to use this API
Authenticate with an App API key. Legacy (v1) API keys are rejected with a400 error that starts with:
Request is malformed: This endpoint does not accept legacy (v1) API keys. Please use a v2 API key.
Optional filters
Only export users in this segment. Send the segment’s UUID, as returned by View segments. Cannot be sent with
segment_name.Set to
true to include every user in the segment. Defaults to false when you send a segment, so the export only includes the segment’s subscribed users: users with a subscribed Subscription that matches the segment’s filters. Defaults to true when you do not send a segment, so the export includes every user in the app. Setting it to false without a segment exports only users with at least one subscribed Subscription. See Subscription statuses.extra_fields returns a 400 error. Other Export subscriptions CSV parameters, such as last_active_since, are ignored.
Example request
cURL
curl --request POST \
--url https://api.onesignal.com/apps/YOUR_APP_ID/users/csv_export \
--header 'Authorization: Key YOUR_APP_API_KEY' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '{"segment_id": "YOUR_SEGMENT_ID"}'
Example successful response
200 OK
{
"csv_file_url": "https://onesignal.com/csv_exports/YOUR_APP_ID/onesignal_users_0f1e2d3c4b5a69788796a5b4c3d2e1f0.csv.gz"
}
onesignal_users_.
File readiness
- The export runs in the background after the API responds. The
csv_file_urlreturns404until the file is uploaded. - Poll the URL at intervals until the file downloads. Large apps take longer to export.
- The file remains available for 3 days after generation.
- Only one export per OneSignal account can run at a time. The limit is shared with Export subscriptions CSV. A request while another export is running returns
429.
CSV data contents
Every export has these columns, in this order.| Column | Description |
|---|---|
onesignal_id | The user’s OneSignal ID. |
external_id | The user’s External ID, if set. |
tags | The user’s Tags as a JSON object, for example {"plan":"pro"}. |
language_code | The user’s language in ISO 639-1 format. en when the language is not set. |
timezone_id | The user’s timezone in IANA format. |
ip_address | The user’s last known IP address, if detected. IPv4 or IPv6. |
lat | The user’s latitude with 6 decimal places, if location is collected. |
lon | The user’s longitude with 6 decimal places, if location is collected. |
first_session | When the user was first active, in UTC as YYYY-MM-DD HH:MM:SS. |
last_session | When the user was last active, in UTC as YYYY-MM-DD HH:MM:SS. |
Errors
| Status | When |
|---|---|
400 | The request uses a legacy (v1) API key, the app is not in the user-based segmentation beta, segment_id and segment_name are both sent, either segment field is not a string, segment_id is not a valid UUID, the segment does not exist, or the body contains extra_fields. |
401 | The API key is missing or invalid. |
403 | Exports are disabled because the app exceeded a limit. See Disabled apps. |
429 | Another users or subscriptions export is already running for your account. Wait for it to finish, then retry. |
errors:
400 Bad Request
{
"success": false,
"errors": ["'segment_id' The provided segment does not exist"]
}
FAQ
Why does csv_file_url return 404?
The file is not ready yet. The export runs after the API responds, and the URL returns 404 until the upload finishes. Poll the URL until the file downloads.
Why did I get “This endpoint does not accept legacy (v1) API keys”?
The request used a legacy API key. Create an App API key and send it in theAuthorization header as Key YOUR_APP_API_KEY.
How is this different from the subscriptions export?
The users export has one row per user with user-level data. The subscriptions export has one row per Subscription, with fields such as push token, email address, phone number, and device type.Headers
Your App API key with prefix Key. Legacy (v1) API keys are rejected with a 400 error. See Keys & IDs.
Path Parameters
Your OneSignal App ID in UUID v4 format. See Keys & IDs.
Body
application/json
Was this page helpful?