Chilkat Online Tools

Swift / Braze Endpoints / User Profile Export by Identifier

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.

    // {
    //   "external_ids": [
    //     "user_identifier1",
    //     "user_identifier2"
    //   ],
    //   "user_aliases": [
    //     {
    //       "alias_name": "example_alias",
    //       "alias_label": "example_label"
    //     }
    //   ],
    //   "device_id": "1234567",
    //   "braze_id": "braze_identifier",
    //   "email_address": "example@braze.com",
    //   "phone": "+11112223333",
    //   "fields_to_export": [
    //     "first_name",
    //     "email",
    //     "purchases"
    //   ]
    // }

    let json = CkoJsonObject()
    json.UpdateString("external_ids[0]", value: "user_identifier1")
    json.UpdateString("external_ids[1]", value: "user_identifier2")
    json.UpdateString("user_aliases[0].alias_name", value: "example_alias")
    json.UpdateString("user_aliases[0].alias_label", value: "example_label")
    json.UpdateString("device_id", value: "1234567")
    json.UpdateString("braze_id", value: "braze_identifier")
    json.UpdateString("email_address", value: "example@braze.com")
    json.UpdateString("phone", value: "+11112223333")
    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")

    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/ids", 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 '{
  "external_ids": ["user_identifier1", "user_identifier2"],
  "user_aliases": [{
    "alias_name": "example_alias",
    "alias_label": "example_label"
  }],
  "device_id": "1234567",
  "braze_id": "braze_identifier",
  "email_address": "example@braze.com",
  "phone": "+11112223333",
  "fields_to_export": ["first_name", "email", "purchases"]
}'
https://rest.iad-01.braze.com/users/export/ids

Postman Collection Item JSON

{
  "name": "User Profile Export by Identifier",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{api_key}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"external_ids\": [\"user_identifier1\", \"user_identifier2\"],\n  \"user_aliases\": [{\n    \"alias_name\": \"example_alias\",\n    \"alias_label\": \"example_label\"\n  }],\n  \"device_id\": \"1234567\",\n  \"braze_id\": \"braze_identifier\",\n  \"email_address\": \"example@braze.com\",\n  \"phone\": \"+11112223333\",\n  \"fields_to_export\": [\"first_name\", \"email\", \"purchases\"]\n}"
    },
    "url": {
      "raw": "https://{{instance_url}}/users/export/ids",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "users",
        "export",
        "ids"
      ]
    },
    "description": "This endpoint allows you to export data from any user profile by specifying a form of user identifier. Up to 50 `external_ids` or `user_aliases` can be included in a single request. Should you want to specify `device_id` or `email_address` only one of either identifier can be included per request..\n\n## Request Parameters\n\n| Key | Requirement | Data Type | Details |\n|-----|-----|-----|-----|\n|`external_ids` | Optional | Array of strings | External identifiers for users you wish export |\n|`user_aliases` | Optional | Array of user alias object | User aliases for users to export |\n|`device_id` | Optional | String | Device identifier as returned by various SDK methods such as `getDeviceId` |\n|`braze_id` | Optional | String | Braze identifier for a particular user |\n|`email_address` | Optional | String | Email address of user |\n|`phone` | Optional | String | Phone number of user |\n|`fields_to_export` | Optional | Array of strings | Name of user data fields to export. Defaults to all if not provided |\n\n### Request Component\n- [User Alias Object](https://www.braze.com/docs/api/objects_filters/user_alias_object/)\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\nPlease be aware that the `/users/export/ids` endpoint will pull together the entire user profile for this user, including data such as all campaigns and canvases received, all custom events performed, all purchases made, and all custom attributes. As a result, this endpoint is slower than other REST API endpoints.\n\nDepending on the data requested, this API endpoint may have not be able to fulfill your hourly API rate limit. If you anticipate using this endpoint regularly to export users, instead consider exporting users by segment, which is asynchronous and more optimized for larger data pulls. Documentation on that endpoint is below.\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    \"users\" : (array of object) the data for each of the exported users, may be empty if no users are found,\n    \"invalid_user_ids\" : (optional, array of string) each of the identifiers provided in the request that did not correspond to a known user\n}\n```\n\nFor an example of the data that is accessible via this endpoint see the example below.\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\" : (integer),\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_triggered_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": [
  ]
}