Chilkat Online Tools

C / Braze Endpoints / Create New User Aliases

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;

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

    http = CkHttp_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 = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"user_aliases[0].external_id","external_identifier");
    CkJsonObject_UpdateString(json,"user_aliases[0].alias_name","example_name");
    CkJsonObject_UpdateString(json,"user_aliases[0].alias_label","example_label");

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

    resp = CkHttp_PostJson3(http,"https://rest.iad-01.braze.com/users/alias/new","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_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": [
  ]
}