Retrieving profiles
After a snapshot operation completes, you can retrieve its matching profiles from the Snapshot Profiles endpoint.
1curl -X GET 'https://audiences.twilio.com/preview/CohortSnapshots/cmp_cohortsnapshot_01h9d8r0vte3hz8tykdj329t7r/Profiles' \2-u $TWILIO_API_KEY:$TWILIO_API_SECRET
Each profile entry includes a profileId and a variables object that contains the data fields you projected when you created the snapshot. If you omitted variables during creation, only profileId is returned.
1{2"profiles": [3{4"profileId": "mem_profile_01h9d8r0vte3hz8tykdj329t7r",5"variables": {6"email": "jane@example.com"7}8}9],10"meta": {11"key": "profiles",12"pageSize": 50,13"nextToken": "eyJvZmZzZXQiOjUwfQ"14}15}
The meta.nextToken field appears whenever additional pages remain. Pass its value back as the pageToken query parameter to fetch the next page. Continue this process until nextToken is no longer present in the response.
For snapshots that match many profiles, Twilio splits the results across multiple partitions so that you can retrieve them with parallel worker threads.
First, request the snapshot resource to determine its partitionCount.
1curl -X GET 'https://audiences.twilio.com/preview/CohortSnapshots/cmp_cohortsnapshot_01h9d8r0vte3hz8tykdj329t7r' \2-u $TWILIO_API_KEY:$TWILIO_API_SECRET
Sample response:
1{2"cohortSnapshotId": "cmp_cohortsnapshot_01h9d8r0vte3hz8tykdj329t7r",3"partitionCount": 4,4"profileCount": 42000,5"labels": {6"key": "value"7}8}
Then request each partition independently by using the partition query parameter:
1curl -X GET 'https://audiences.twilio.com/preview/CohortSnapshots/cmp_cohortsnapshot_01h9d8r0vte3hz8tykdj329t7r/Profiles?partition=0' \2-u $TWILIO_API_KEY:$TWILIO_API_SECRET
By default, Cohorts calculates the optimal partitionCount based on the snapshot's total profile volume.
Info
If your downstream processing architecture requires a specific thread count or chunk size, you can pass partitionCountOverride (up to 500) when you call Create Snapshot. You can also pass profileLimit if you want to retrieve only a capped sample of matching profiles.
- Zero-based indexing: Partition indices are zero-based, ranging from
0throughpartitionCount - 1. Passing an index outside this range returns HTTP400 Bad Request. - Independent pagination: Each partition paginates independently by using
pageTokenuntil its ownnextTokenfield is absent. - No duplicate profiles: Retrieving partitions in parallel is thread-safe and ensures that no profile appears in more than one partition.
- Empty partitions: When you set the
partitionCountOverrideparameter, some partitions might not contain any profiles. This happens when you request more partitions than there are matching profiles to distribute. For example, if you setpartitionCountOverrideto 500 and the snapshot contains 10 profiles, most partitions are empty. If you request one of these partitions, the response includes an empty profiles array ("profiles": []). Consider the partition complete and proceed to the next partition.
- See the Cohorts API reference.
- Learn about Rate limits.