It's not uncommon for user IDs for the same user to differ across projects within the same organization. The user mapping (aliasing) API lets you map users with different user IDs together in Amplitude.
In this example, three user records, each with a different user ID, are all merged into the user ID hank@globex.net
. This new user ID is that user's "global" user ID in the cross-project view. This way, you can get an accurate count of the number of unique users across your entire product portfolio.
This API uses your API key passed in the body of the request:
api-key=API_KEY
For more information, see Find your API Credentials
Region | Endpoint |
---|---|
Standard server | https://api.amplitude.com/usermap |
Keep these considerations in mind when using this API.
user_id
and aren't transferred between User 1 and User 2.The aliasing API has the following limits:
Name |
Description |
---|---|
api_key |
Required. String. an API Key for any project in your organization. |
mapping |
Required. Either a single JSON mapping object or an array of JSON objects, each of which represents a single mapping. |
Name |
Description |
---|---|
user_id |
Required. String. A UUID (unique user ID) specified by you, for the user you want to map. Each JSON mapping object can contain one user_id to map. |
global_user_id |
Required unless unmap is true. String. A UUID (unique user ID) specified by you. The unified identity you want to map the other user_id to. |
unmap |
Optional. Boolean. When true, the current mapping for user_id is removed. |
Map a user ID to a global user ID. Remember that you can map a single user ID per JSON mapping object.
This is a basic request with only the required parameters. See the examples below for more detailed requests.
1curl --location -g --request POST 'https://api.amplitude.com/usermap?mapping=[{"user_id":"<USER_ID", "global_user_id": "<GLOBAL_USER_ID"}]&api_key=API_KEY'
1POST /usermap?mapping=[{"user_id":"<USER_ID", "global_user_id": "<GLOBAL_USER_ID"}]&api_key=API_KEY2HTTP/1.13Host: api.amplitude.com
Example: Map a user ID to a global user ID
Example: Map multiple users in one request
This is a basic request with only the required parameters. Remember that you can unmap a single user ID per JSON mapping object. See the examples below for more detailed requests.
1curl --location -g --request POST 'https://api.amplitude.com/usermap?mapping=[{"user_id":"<USER_ID", "unmap": true}]&api_key=API_KEY'
1POST /usermap?mapping=[{"user_id":"<USER_ID>", "unmap": true}]&api_key=API_KEY2HTTP/1.13Host: api.amplitude.com
Example: Unmap a user ID
Get the list of mappings that involve the provided user ids.
User mappings uses a different URL than the map and unmap endpoints above, https://amplitude.com/api/2/usermap
.
1user_ids = ["<REPLACE ME WITH LIST OF USER IDS>"] 2 3request_data = { 4 "user_ids": user_ids, 5} 6url = 'https://amplitude.com/api/2/usermap' 7 8API_KEY = "REPLACE_ME" 9SECRET_KEY = "REPLACE_ME"10result = requests.get(url, auth=HTTPBasicAuth(API_KEY, SECRET_KEY), data=request_data)11if result.status_code != 200:12 raise AssertionError(13 "Request failed. Error: code - %s, text - %s" % (result.status_code, result.text))14else:15 print(result.json())
Name |
Description |
---|---|
api_key |
Required. String. an API Key for any project in your organization. |
secret_key |
Required. String. an API Secret Key for any project in your organization. |
user_ids |
Required. A list of user ids. Minimum 1 user id, maximum 100 user ids in a single request. |
The response for a POST request contains these fields:
Name |
Description |
---|---|
user id |
A user id in the request list. |
mappings |
The mappings associated with this user id. See next section. Empty if the requested user isn't found |
The mappings
key contains these fields:
Name |
Description |
---|---|
amplitude_id |
The Amplitude ID of the requested user |
mapped_from |
A list of objects that map into the requested user. {"amplitude_id": 1234, "user_id": "mappedUser"} |
mapped_to |
A list of objects that the requested user maps into {"amplitude_id": 1234, "user_id": "globalUser"} |
1 { 2 "user1": 3 { 4 "mapped_from": [{ 5 "amplitude_id": 1234567, 6 "user_id": "user3" 7 }], 8 "mapped_to": [{ 9 "amplitude_id": 1234567,10 "user_id": "user2"11 }]12 },13 "user2":14 {15 "mapped_from": [{16 "amplitude_id": 9988676,17 "user_id": "user1"18 }],19 "mapped_to": []20 }21}
Thanks for your feedback!
May 21st, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.