Chilkat Online Tools

SQL Server / Braze Endpoints / Identify Users

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.

    -- {
    --   "aliases_to_identify": [
    --     {
    --       "external_id": "external_identifier",
    --       "user_alias": {
    --         "alias_name": "example_alias",
    --         "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, 'aliases_to_identify[0].external_id', 'external_identifier'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'aliases_to_identify[0].user_alias.alias_name', 'example_alias'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'aliases_to_identify[0].user_alias.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/identify', '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 '{
  "aliases_to_identify" : 
  [
    {
      "external_id": "external_identifier",
      "user_alias" : {
          "alias_name" : "example_alias",
          "alias_label" : "example_label"
      }
    }
  ]
}'
https://rest.iad-01.braze.com/users/identify

Postman Collection Item JSON

{
  "name": "Identify Users",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "type": "text",
        "value": "Bearer {{api_key}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"aliases_to_identify\" : \n  [\n    {\n      \"external_id\": \"external_identifier\",\n      \"user_alias\" : {\n          \"alias_name\" : \"example_alias\",\n          \"alias_label\" : \"example_label\"\n      }\n    }\n  ]\n}"
    },
    "url": {
      "raw": "https://{{instance_url}}/users/identify",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "users",
        "identify"
      ]
    },
    "description": "Use this endpoint to identify an unidentified (alias-only) user.\n\n> Identifying a user requires an `external_id` to be included in the aliases to identify the object. If the `external_id` is not a valid or known ID, it will simply be added to the aliases user's record, and the user will be considered identified.<br><br>Subsequently, you can associate multiple additional user aliases with a single `external_id`. When these subsequent associations are made, only the push tokens and message history associated with the user alias are retained; any attributes, events or purchases will be \"orphaned\" and not available on the identified user. One workaround is to export the aliased user's data before identification using the `/users/export/ids` endpoint, then re-associate the attributes, events, and purchases with the identified user.<br><br>You can add up to 50 user aliases per request.\n\n### Parameters\n| Parameter | Required | Data Type | Description |\n| -----------|----------| --------|------- |\n| `aliases_to_identify` | Yes | Array of aliases to identify object | See alias to identify object |\n\n### Request Components\n- [Alias to Identify Object](https://www.braze.com/docs/api/objects_filters/aliases_to_identify/)\n- [User Alias Object](https://www.braze.com/docs/api/objects_filters/user_alias_object/)\n<br><br>\n\n### Aliases to Identify Object Specification\n```json\n{\n  \"external_id\" : (required, string) see External User ID below,\n  // external_ids for users that do not exist will return a non-fatal error. \n  // See Server Responses for details.\n  \"user_alias\" : {\n    \"alias_name\" : (required, string),\n    \"alias_label\" : (required, string)\n  }\n}\n```"
  },
  "response": [
  ]
}