SQL Server / Braze Endpoints / Create New User Aliases
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- 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"
-- }
-- ]
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'user_aliases[0].external_id', 'external_identifier'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'user_aliases[0].alias_name', 'example_name'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'user_aliases[0].alias_label', 'example_label'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
-- Adds the "Authorization: Bearer {{api_key}}" header.
EXEC sp_OASetProperty @http, 'AuthToken', '{{api_key}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://rest.iad-01.braze.com/users/alias/new', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
END
GO
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": [
]
}