Chilkat Online Tools

C++ / Braze Endpoints / Create New User Aliases

Back to Collection Items

#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http;
    bool success;

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

    // The following JSON is sent in the request body.

    // {
    //   "user_aliases": [
    //     {
    //       "external_id": "external_identifier",
    //       "alias_name": "example_name",
    //       "alias_label": "example_label"
    //     }
    //   ]
    // }

    CkJsonObject json;
    json.UpdateString("user_aliases[0].external_id","external_identifier");
    json.UpdateString("user_aliases[0].alias_name","example_name");
    json.UpdateString("user_aliases[0].alias_label","example_label");

    http.SetRequestHeader("Content-Type","application/json");
    // Adds the "Authorization: Bearer {{api_key}}" header.
    http.put_AuthToken("{{api_key}}");

    CkHttpResponse *resp = http.PostJson3("https://rest.iad-01.braze.com/users/alias/new","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    std::cout << resp->get_StatusCode() << "\r\n";
    std::cout << resp->bodyStr() << "\r\n";
    delete resp;
    }

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Authorization: Bearer {{api_key}}"
	-d '{
	"user_aliases" : 
	[
		{
			"external_id": "external_identifier",
			"alias_name" : "example_name",
			"alias_label" : "example_label"
		}
	]
}'
https://rest.iad-01.braze.com/users/alias/new

Postman Collection Item JSON

{
  "name": "Create New User Aliases",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "type": "text",
        "value": "Bearer {{api_key}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"user_aliases\" : \n\t[\n\t\t{\n\t\t\t\"external_id\": \"external_identifier\",\n\t\t\t\"alias_name\" : \"example_name\",\n\t\t\t\"alias_label\" : \"example_label\"\n\t\t}\n\t]\n}"
    },
    "url": {
      "raw": "https://{{instance_url}}/users/alias/new",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "users",
        "alias",
        "new"
      ]
    },
    "description": "Use this endpoint to add new user aliases for existing identified users, or to create new unidentified users.\n\n> __Adding a user alias for an existing user__ requires an `external_id` to be included in the new user alias object. If the `external_id` is present in the object but there is no user with that `external_id`, the alias will not be added to any users. If an `external_id` is not present, a user will still be created, but will need to be identified later. You can do this using the \"Identifying Users\" and the `users/identify` endpoint<br><br>__Creating a new alias-only user__ requires the `external_id` to be omitted from the new user alias object. Once the user is created, use the `/users/track` endpoint to associate the alias-only user with attributes, events and purchases, and the `/users/identify` endpoint to identify the user with an `external_id`.\n\n### Request Parameters\n\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n| `user_aliases` | Yes | Array of new user alias objects | See user alias object |\n\n### Request Components\n- [User Alias Object](https://www.braze.com/docs/api/objects_filters/user_alias_object/)<br><br>\nFor more information on `alias_name` and `alias_label`, check out our [User Aliases documentation](https://www.braze.com/docs/user_guide/data_and_analytics/user_data_collection/user_profile_lifecycle/#user-aliases)."
  },
  "response": [
  ]
}