Chilkat Online Tools

Android / Braze Endpoints / Create New User Aliases

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean 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 = new CkJsonObject();
    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) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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