Chilkat Online Tools

unicodeC / Braze Endpoints / Create New User Aliases

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    // 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"
    //     }
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"user_aliases[0].external_id",L"external_identifier");
    CkJsonObjectW_UpdateString(json,L"user_aliases[0].alias_name",L"example_name");
    CkJsonObjectW_UpdateString(json,L"user_aliases[0].alias_label",L"example_label");

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

    resp = CkHttpW_PostJson3(http,L"https://rest.iad-01.braze.com/users/alias/new",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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": [
  ]
}