Swift / Braze Endpoints / User Profile Export by Segment
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()
var success: Bool
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "segment_id": "segment_identifier",
// "callback_endpoint": "example_endpoint",
// "fields_to_export": [
// "first_name",
// "email",
// "purchases"
// ],
// "output_format": "zip"
// }
let json = CkoJsonObject()
json.UpdateString("segment_id", value: "segment_identifier")
json.UpdateString("callback_endpoint", value: "example_endpoint")
json.UpdateString("fields_to_export[0]", value: "first_name")
json.UpdateString("fields_to_export[1]", value: "email")
json.UpdateString("fields_to_export[2]", value: "purchases")
json.UpdateString("output_format", value: "zip")
http.SetRequestHeader("Content-Type", value: "application/json")
// Adds the "Authorization: Bearer {{api_key}}" header.
http.AuthToken = "{{api_key}}"
var resp: CkoHttpResponse? = http.PostJson3("https://rest.iad-01.braze.com/users/export/segment", contentType: "application/json", json: json)
if http.LastMethodSuccess == false {
print("\(http.LastErrorText)")
return
}
print("\(resp!.StatusCode.intValue)")
print("\(resp!.BodyStr)")
resp = nil
}
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Authorization: Bearer {{api_key}}"
-d '{
"segment_id" : "segment_identifier",
"callback_endpoint" : "example_endpoint",
"fields_to_export" : ["first_name", "email", "purchases"],
"output_format" : "zip"
}'
https://rest.iad-01.braze.com/users/export/segment
Postman Collection Item JSON
{
"name": "User Profile Export by Segment",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{api_key}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"segment_id\" : \"segment_identifier\",\n \"callback_endpoint\" : \"example_endpoint\",\n \"fields_to_export\" : [\"first_name\", \"email\", \"purchases\"],\n \"output_format\" : \"zip\"\n}"
},
"url": {
"raw": "https://{{instance_url}}/users/export/segment",
"protocol": "https",
"host": [
"{{instance_url}}"
],
"path": [
"users",
"export",
"segment"
]
},
"description": "This endpoint allows you to export all the users within a segment. User data is exported as multiple files of user JSON objects separated by new lines (i.e. one JSON object per line).\n\n> Beginning April 2021, the \"fields_to_export\" field in this API request will be __required for all new accounts__. The option to default to all field will be removed, and new customers will need to specify the specific fields they'd like to include in their export.\n\n## Request Parameters\n\n| Key | Requirement | Data Type | Details |\n|---|---|---|---|\n|`segment_id` | Required | String | Identifier for the segment to be exported |\n|`callback_endpoint` | Optional | String | Endpoint to post a download url to when the export is available |\n|`fields_to_export` | Required* | Array of Strings | Name of user data fields to export, you may also export custom attributes. *Beginning April 2021, new accounts must specify specific fields to export. |\n|`output_format` | Optional | String | When using your own S3 bucket, allows to specify file format as 'zip' or 'gzip'. Defaults to zip file format |\n\n### Components Used\n- [Segment Identifier](https://www.braze.com/docs/api/identifier_types/)\n\n\n### Fields to Export\n\nThe following is a list of valid `fields_to_export`. Using `fields_to_export` to minimize the data returned can improve response time of this API endpoint:\n\n* `apps`\n* `attributed_campaign`\n* `attributed_source`\n* `attributed_adgroup`\n* `attributed_ad`\n* `braze_id`\n* `campaigns_received`\n* `canvases_received`\n* `cards_clicked`\n* `country`\n* `created_at`\n* `custom_attributes`\n* `custom_events`\n* `devices`\n* `dob`\n* `email`\n* `email_subscribe`\n* `external_id`\n* `first_name`\n* `gender`\n* `home_city`\n* `language`\n* `last_coordinates`\n* `last_name`\n* `phone`\n* `purchases`\n* `push_subscribe`\n* `push_tokens`\n* `random_bucket`\n* `time_zone`\n* `total_revenue`\n* `uninstalled_at`\n* `user_aliases`\n\n### Response\n\n```json\nContent-Type: application/json\nAuthorization: Bearer YOUR-REST-API-KEY\n{\n \"message\": (required, string) the status of the export, returns 'success' when completed without errors,\n \"object_prefix\": (required, string) the filename prefix that will be used for the JSON file produced by this export, e.g. 'bb8e2a91-c4aa-478b-b3f2-a4ee91731ad1-1464728599',\n \"url\" : (optional, string) the URL where the segment export data can be downloaded if you do not have your own S3 credentials\n}\n```\n\nOnce made available, the URL will only be valid for a few hours. As such, we highly recommend that you add your own S3 credentials to Braze.\n\n### Sample User Export File Output\n\nUser export object (we will include the least data possible - if a field is missing from the object it should be assumed to be null, false, or empty):\n\n```json\n{\n \"external_id\" : (string),\n \"user_aliases\" : [\n {\n \"alias_name\" : (string),\n \"alias_label\" : (string)\n }\n ],\n \"braze_id\": (string),\n \"first_name\" : (string),\n \"last_name\" : (string),\n \"email\" : (string),\n \"dob\" : (string) date for the user's date of birth,\n \"home_city\" : (string),\n \"country\" : (string),\n \"phone\" : (string),\n \"language\" : (string) ISO-639 two letter code,\n \"time_zone\" : (string),\n \"last_coordinates\" : (array of float) [lon, lat],\n \"gender\" : (string) \"M\" | \"F\",\n \"total_revenue\" : (float),\n \"attributed_campaign\" : (string),\n \"attributed_source\" : (string),\n \"attributed_adgroup\" : (string),\n \"attributed_ad\" : (string),\n \"push_subscribe\" : (string) \"opted_in\" | \"subscribed\" | \"unsubscribed\",\n \"email_subscribe\" : (string) \"opted_in\" | \"subscribed\" | \"unsubscribed\",\n \"custom_attributes\" : (object) custom attribute key value pairs,\n \"custom_events\" : [\n {\n \"name\" : (string),\n \"first\" : (string) date,\n \"last\" : (string) date,\n \"count\" : (int)\n },\n ...\n ],\n \"purchases\" : [\n {\n \"name\" : (string),\n \"first\" : (string) date,\n \"last\" : (string) date,\n \"count\" : (int)\n },\n ...\n ],\n \"devices\" : [\n {\n \"model\" : (string),\n \"os\" : (string),\n \"carrier\" : (string),\n \"idfv\" : (string) only included for iOS devices,\n \"idfa\" : (string) only included for iOS devices when IDFA collection is enabled,\n \"google_ad_id\" : (string) only included for Android devices when Google Play Advertising Identifier collection is enabled,\n \"roku_ad_id\" : (string) only included for Roku devices,\n \"windows_ad_id\" : (string) only included for Windows devices,\n \"ad_tracking_enabled\" : (bool)\n },\n ...\n ],\n \"push_tokens\" : [\n {\n \"app\" : (string) app name,\n \"platform\" : (string),\n \"token\" : (string)\n },\n ...\n ],\n \"apps\" : [\n {\n \"name\" : (string),\n \"platform\" : (string),\n \"version\" : (string),\n \"sessions\" : (string),\n \"first_used\" : (string) date,\n \"last_used\" : (string) date\n },\n ...\n ],\n \"campaigns_received\" : [\n {\n \"name\" : (string),\n \"last_received\" : (string) date,\n \"engaged\" : {\n \"opened_email\" : (bool),\n \"opened_push\" : (bool),\n \"clicked_email\" : (bool),\n \"clicked_in_app_message\" : (bool)\n },\n \"converted\" : (bool),\n \"api_campaign_id\" : (string),\n \"variation_name\" : (optional, string) exists only if it is a multivariate campaign,\n \"variation_api_id\" : (optional, string) exists only if it is a multivariate campaign,\n \"in_control\" : (optional, bool) exists only if it is a multivariate campaign\n },\n ...\n ],\n \"canvases_received\": [\n {\n \"name\": (string),\n \"api_canvas_id\": (string),\n \"last_received_message\": (string) date,\n \"last_entered\": (string) date,\n \"variation_name\": (string),\n \"in_control\": (bool),\n \"last_exited\": (string) date,\n \"steps_received\": [\n {\n \"name\": (string),\n \"api_canvas_step_id\": (string),\n \"last_received\": (string) date\n },\n {\n \"name\": (string),\n \"api_canvas_step_id\": (string),\n \"last_received\": (string) date\n },\n {\n \"name\": (string),\n \"api_canvas_step_id\": (string),\n \"last_received\": (string) date\n }\n ]\n },\n ...\n ],\n \"cards_clicked\" : [\n {\n \"name\" : (string)\n },\n ...\n ]\n}\n```"
},
"response": [
]
}