User Segments Export API (Deprecated)

One of the most powerful pieces of functionality Analytics offers is the ability to identify groups of users based on their behavioral characteristics. These groups are known in Analytics as User Segments. This functionality is now available as an API so that you can programmatically export segments for use within your own or third-party platforms.

Introduction

Almost any data point in Analytics can be saved as a User Segment. For example, if you run a segmentation query representing Registrations in the Last 7 Days, you can save the output of that query as a User Segment named Recent Registrants, which will contain all users who performed a Registration event in the Last 7 Days. Once these User Segments are built, they can be used as filters in all other queries. Continuing on the above example, you would be able to filter any analysis based on whether users included in that analysis are in (or not in) the Recent Registrants set of users.

Using Analytics’ User Segments Export API, you will be able to export your User Segments for use in downstream systems.

Analytics’ Export API is accessible only to Pro or Enterprise customers.

Overview

The User Segments Export API is an asynchronous API. Upon invoking a request for a User Segments export, Analytics will schedule a job to asynchronously process and upload the final result to Amazon S3, where you’ll then be able to download the file to access the contents.

Analytics’ User Segments Export API allows you to perform three operations related to User Segment exports:

  • List all User Segments in a project
  • Request an export of a User Segment
  • Check the status of requested User Segment export

User Segment exports typically complete within a matter of seconds, but can potentially take up to several hours to complete with a large result set.

The expected usage of this API works as follows:

  1. List your User Segments and identify the User Segment you would like to export.
  2. Submit a request to export a User Segment by passing in the unique identifier of the User Segment from the prior step. You will receive an Export Request Token uniquely identifying your export request.
  3. Poll Analytics’ API using your Export ID. Once the upload has been completed, the API response will include a successful status and a URL to a file in Amazon S3 containing the users in your User Segment.
  4. Download the newly uploaded file in S3.

Common Requests and Response

Authentication

Analytics’ Export API requires HTTPS/SSL and uses Basic Authentication header for all requests. Basic Authentication is a simple authentication scheme built into the HTTP protocol. The client sends HTTP requests with the Authorization header that contains the word Basic followed by a space and a Base64-encoded string username:password.

Use your API Key as the username and your Access Token as the password. This information can be found on the Project Page in the Analytics web application. Please treat your Access Token as you would a password, as it is meant to only be known to you.

An example curl: curl -v -u "apiKey:accessToken" https://query.indicative.com

curl’s -u parameter automatically encodes the username and password and inserts them into the Authorization header. Depending on your client implementation you may need to do this manually.

The resulting HTTP Response should have a 200 OK status.

Response Format

All API responses are in JSON format.

Common Response Codes

Status Code Description
200 Success: Your request was successful.
401 Unauthorized: Your request was rejected because we could not validate your credentials. Please check that your API key and access token are correct.
403 Forbidden: Your request was rejected because the specified project does not have access to the Export API. Please upgrade your account or contact Analytics support to gain access.
429 Too Many Requests: Too many requests have been attempted in a given amount of time.
500 Internal Error: An error occurred while processing your API request. This will automatically raise a ticket with the Analytics team. Please try your request at a later time.

Endpoints

List User Segments

This endpoint lists all User Segments in a project.

User Segment Object Response

Field Type Nullable? Description
segmentId String No The unique ID of the User Segment.
name String No The human-readable name of the User Segments.
description String Yes The human-readable description of the User Segments.
category String Yes The human-readable category of the User Segments.
projectId String No The project ID associated to the segment ID.
type Enum No The type of the user segment, either Static (One-time in the UI) or Dynamic (Daily in the UI). Static segments never change while Dynamic segments may be refreshed.
lastRun DateTime Yes The timestamp of the last refresh of the User Segments.

Example: List User Segments

$ curl -s -u "5a6646c4-ae5a-4de4-9d47-eb6f228405b2:nux06hkn870v0ni4fhtd81kf" https://query.indicative.com/service/v1/segments/list

[
  {
    "segmentId": "82200474-c131-4f7b-a35e-381469af31a7",
    "name": "My Segment",
    "description": "This is my segment",
    "category": null,
    "projectId": "5a6646c4-ae5a-4de4-9d47-eb6f228405b2",
    "type": "Static",
    "lastRun": "2019-04-09T12:25:06.000Z"
  }
]

Request a User Segment Export

This endpoint invokes a new export request for the specified User Segments.

  • Endpoint: POST https://query.indicative.com/service/v1/segments/export/
  • Request Parameters: POST body, containing the following fields:

    • segmentId: the ID of the segment to export
    • outputFormat: the output format of the export file (currently only CSV is supported)
  • Request Headers:

    • Basic Authentication
    • Content-Type: application/json
  • Response: An Export Status object representing the status of the newly created export. See Export Status Object Response

Export Status Object Response

Field Type Nullable? Description
exportId String No The unique ID of the User Segment export request.
segment Object No An object encapsulating information about the target User Segment for this export.
status Enum No The status of the User Segment export. Values are either PENDING, COMPLETE, or FAILED.
projectId String No The project ID of the User Segment export.
startTime DateTime No The time at which the User Segment export started.
endTime DateTime Yes The time at which the User Segment export completed. This field will remain null until the export is completed.
filename String No The fully qualified location of the file to download.

Example: Request User Segments Export

$ curl -s -u "5a6646c4-ae5a-4de4-9d47-eb6f228405b2:nux06hkn870v0ni4fhtd81kf" -H 'Content-Type: application/json' https://query.indicative.com/service/v1/segments/export/ -d'{
  "segmentId": "82200474-c131-4f7b-a35e-381469af31a7",
  "outputFormat": "csv"
}'
{
  "exportId": "8f9fdd71-204c-41e1-a2ab-de7f85002f65",
  "segment": {
    "segmentId": "82200474-c131-4f7b-a35e-381469af31a7",
    "name": "My Segment",
    "description": "This is my segment",
    "category": null,
    "projectId": "5a6646c4-ae5a-4de4-9d47-eb6f228405b2",
    "type": "Static",
    "lastRun": "2019-04-09T12:25:06.000Z"
  },
  "status": "PENDING",
  "startTime": "2019-04-09T14:45:07.000Z",
  "endTime": null,
  "filename": null
}

Check Export Status

This endpoint checks the status of a previously submitted export request. Once the request has finished processing, it will include a URL to download the results.

Once the request has been completed, the file will remain in Amazon for no more than 48 hours. Otherwise, a new request must be submitted.

  • Endpoint: GET https://query.indicative.com/service/v1/segments/export/{exportId}
  • Request Parameters:

    • exportId: the unique identifier of the export for which to check status retrieved from either the Status or List API
  • Request Headers: Basic Authentication
  • Response: An Export Status object representing the status of the specified export. See Export Status Object Response.

Example: Check User Segment Export Status

$ curl -s -u "5a6646c4-ae5a-4de4-9d47-eb6f228405b2:nux06hkn870v0ni4fhtd81kf" https://query.indicative.com/service/v1/segments/export/8f9fdd71-204c-41e1-a2ab-de7f85002f65

{
  "exportId": "8f9fdd71-204c-41e1-a2ab-de7f85002f65",
  "segment": {
    "segmentId": "82200474-c131-4f7b-a35e-381469af31a7",
    "name": "My Segment",
    "description": "This is my segment",
    "category": null,
    "projectId": "5a6646c4-ae5a-4de4-9d47-eb6f228405b2",
    "type": "Static",
    "lastRun": "2019-04-09T12:25:06.000Z"
  },
  "status": "COMPLETE",
  "startTime": "2019-04-09T14:45:07.000Z",
  "endTime": "2019-04-09T14:45:42.000Z",
  "filename": "s3://upload-bucket/path/to/8f9fdd71-204c-41e1-a2ab-de7f85002f65.csv"
}

Was this page helpful?