Chilkat Online Tools

Foxpro / Braze Endpoints / User Track

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* Use this online tool to generate code from sample JSON: Generate Code to Create JSON

* The following JSON is sent in the request body.

* {
*   "attributes": [
*     {
*       "external_id": "user_identifier",
*       "string_attribute": "fruit",
*       "boolean_attribute_1": true,
*       "integer_attribute": 25,
*       "array_attribute": [
*         "banana",
*         "apple"
*       ]
*     }
*   ],
*   "events": [
*     {
*       "external_id": "user_identifier",
*       "app_id": "app_identifier",
*       "name": "watched_trailer",
*       "time": "2013-07-16T19:20:30+1:00"
*     }
*   ],
*   "purchases": [
*     {
*       "external_id": "user_identifier",
*       "app_id": "app_identifier",
*       "product_id": "product_name",
*       "currency": "USD",
*       "price": 12.12,
*       "quantity": 6,
*       "time": "2017-05-12T18:47:12Z",
*       "properties": {
*         "integer_property": 3,
*         "string_property": "Russell",
*         "date_property": "2014-02-02T00:00:00Z"
*       }
*     }
*   ]
* }

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("attributes[0].external_id","user_identifier")
loJson.UpdateString("attributes[0].string_attribute","fruit")
loJson.UpdateBool("attributes[0].boolean_attribute_1",1)
loJson.UpdateInt("attributes[0].integer_attribute",25)
loJson.UpdateString("attributes[0].array_attribute[0]","banana")
loJson.UpdateString("attributes[0].array_attribute[1]","apple")
loJson.UpdateString("events[0].external_id","user_identifier")
loJson.UpdateString("events[0].app_id","app_identifier")
loJson.UpdateString("events[0].name","watched_trailer")
loJson.UpdateString("events[0].time","2013-07-16T19:20:30+1:00")
loJson.UpdateString("purchases[0].external_id","user_identifier")
loJson.UpdateString("purchases[0].app_id","app_identifier")
loJson.UpdateString("purchases[0].product_id","product_name")
loJson.UpdateString("purchases[0].currency","USD")
loJson.UpdateNumber("purchases[0].price","12.12")
loJson.UpdateInt("purchases[0].quantity",6)
loJson.UpdateString("purchases[0].time","2017-05-12T18:47:12Z")
loJson.UpdateInt("purchases[0].properties.integer_property",3)
loJson.UpdateString("purchases[0].properties.string_property","Russell")
loJson.UpdateString("purchases[0].properties.date_property","2014-02-02T00:00:00Z")

loHttp.SetRequestHeader("Content-Type","application/json")
* Adds the "Authorization: Bearer {{api_key}}" header.
loHttp.AuthToken = "{{api_key}}"

loResp = loHttp.PostJson3("https://rest.iad-01.braze.com/users/track","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJson
    CANCEL
ENDIF

? STR(loResp.StatusCode)
? loResp.BodyStr
RELEASE loResp

RELEASE loHttp
RELEASE loJson

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Authorization: Bearer {{api_key}}"
	-d '{
	"attributes": [ 
 	{
 	  "external_id":"user_identifier",
      "string_attribute": "fruit",
      "boolean_attribute_1": true,
      "integer_attribute": 25,
      "array_attribute": ["banana", "apple"]
    }
    ],
    "events": [
    {
      "external_id": "user_identifier",
      "app_id" : "app_identifier",
      "name": "watched_trailer",
      "time": "2013-07-16T19:20:30+1:00"
    }  
   ],
  "purchases": [
     {
      "external_id": "user_identifier",
      "app_id": "app_identifier",
      "product_id": "product_name",
      "currency": "USD",
      "price": 12.12,
      "quantity": 6,
      "time": "2017-05-12T18:47:12Z",
      "properties": {
         "integer_property": 3,
         "string_property": "Russell",
         "date_property": "2014-02-02T00:00:00Z"
       } 
     }
  ]
}'
https://rest.iad-01.braze.com/users/track

Postman Collection Item JSON

{
  "name": "User Track",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "type": "text",
        "value": "Bearer {{api_key}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"attributes\": [ \n \t{\n \t  \"external_id\":\"user_identifier\",\n      \"string_attribute\": \"fruit\",\n      \"boolean_attribute_1\": true,\n      \"integer_attribute\": 25,\n      \"array_attribute\": [\"banana\", \"apple\"]\n    }\n    ],\n    \"events\": [\n    {\n      \"external_id\": \"user_identifier\",\n      \"app_id\" : \"app_identifier\",\n      \"name\": \"watched_trailer\",\n      \"time\": \"2013-07-16T19:20:30+1:00\"\n    }  \n   ],\n  \"purchases\": [\n     {\n      \"external_id\": \"user_identifier\",\n      \"app_id\": \"app_identifier\",\n      \"product_id\": \"product_name\",\n      \"currency\": \"USD\",\n      \"price\": 12.12,\n      \"quantity\": 6,\n      \"time\": \"2017-05-12T18:47:12Z\",\n      \"properties\": {\n         \"integer_property\": 3,\n         \"string_property\": \"Russell\",\n         \"date_property\": \"2014-02-02T00:00:00Z\"\n       } \n     }\n  ]\n}"
    },
    "url": {
      "raw": "https://{{instance_url}}/users/track",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "users",
        "track"
      ]
    },
    "description": "Use this endpoint to record custom events, purchases, and update user profile attributes.\n\nUser Track has a base speed limit of 50,000 requests per minute for all customers. Each request can contain up to 75 events, 75 attribute updates, and 75 purchases. Each component (event, attribute, and purchase arrays), can update up to 75 users each (max of 225 individual users). Each update can also belong to the same user for a max of 225 updates to a single user in a request. Please see our page on API limits for details, and reach out to your Customer Success Manager if you need your limit increased.\n\nPlease note that Braze processes the data passed via API at face value and customers should only pass deltas (changing data) to minimize unnecessary data point consumption. To read more, check out our [data point documentation](https://www.braze.com/docs/user_guide/onboarding_with_braze/data_points/#data-points).\n\n### Request Parameters\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n| `attributes` | Optional | Array of attributes objects | See user attributes object |\n| `events` | Optional | Array of event objects | See events object |\n| `purchases` | Optional | Array of purchase objects | See purchase object |\n\n### Request Components\n- [User Attributes Object](https://www.braze.com/docs/api/objects_filters/user_attributes_object/)\n- [Events Object](https://www.braze.com/docs/api/objects_filters/event_object/)\n- [Purchases Object](https://www.braze.com/docs/api/objects_filters/purchase_object/)\n\nWhen creating alias-only users through this endpoint, you must explicitly set the `_update_existing_only` flag to `false`.<br><br>Updating the subscription status with this endpoint will not only update the user specified by their external_id (e.g User1), but it will also update the subscription status of any users with the same email as that user (User1).\n\n## User Track Responses\n\nUpon using any of the aforementioned API requests you should receive one of the following three general responses:\n\n#### Successful Message\n\nSuccessful messages will be met with the following response:\n\n```json\n{\n  \"message\" : \"success\",\n  \"attributes_processed\" : (optional, integer), if attributes are included in the request, this will return an integer of the number of external_ids with attributes that were queued to be processed,\n  \"events_processed\" : (optional, integer), if events are included in the request, this will return an integer of the number of events that were queued to be processed,,\n  \"purchases_processed\" : (optional, integer), if purchases are included in the request, this will return an integer of the number of purchases that were queued to be processed,,\n}\n```\n\n#### Successful Message with Non-Fatal Errors\n\nIf your message is successful but has non-fatal errors such as one invalid Event Object out of a long list of events you will receive the following response:\n\n```json\n{\n  \"message\" : \"success\",\n  \"errors\" : [\n    {\n      <minor error message>\n    }\n  ]\n}\n```\n\n#### Message with Fatal Errors\n\nIn the case of a success, any data that was not affected by an error in the _errors_ array will still be processed. If your message has a fatal error you will receive the following response:\n\n```json\n{\n  \"message\" : <fatal error message>,\n  \"errors\" : [\n    {\n      <fatal error message>\n    }\n  ]\n}\n```\n\n#### Queued Responses\n\nDuring times of maintenance, Braze might pause the real-time processing of the API. In these situations, the server will return an HTTP Accepted 202 response code and the following body, which indicates that we have received and queued the API call but have not immediately processed it. All scheduled maintenance will be posted to [http://status.braze.com](http://status.braze.com) ahead of time.\n\n```json\n{\n  \"message\" : \"queued\"\n}\n```\n\n#### Fatal Error Response Codes\n\nThe following status codes and associated error messages will be returned if your request encounters a fatal error. Any of these error codes indicate that no data will be processed.\n\n| Error Code | Reason / Cause |\n| ---------------------| --------------- |\n| `400 Bad Request` | Bad Syntax. |\n| `401 Unauthorized` | Unknown or missing REST API Key. |\n| `404 Not Found` | Unknown REST API Key (if provided). |\n| `429 Rate Limited` | Over rate limit. |\n| `5XX` | Internal server error, you should retry with exponential backoff. |\n\n###  Importing Legacy User Data\n\nYou may submit data through the Braze API for a user who has not yet used your mobile app in order to generate a user profile. If the user subsequently uses the application all information following their identification via the SDK will be merged with the existing user profile you created via the API call. Any user behavior that is recorded anonymously by the SDK prior to identification will be lost upon merging with the existing API generated user profile.\n\nThe segmentation tool will include these users regardless of whether they have engaged with the app. If you want to exclude users uploaded via the User API who have not yet engaged with the app you should add the filter -- `Session Count > 0`.\n"
  },
  "response": [
  ]
}