POST/ users/ merge/
Merge user
You can merge users using REST API. Request requires providing the main user to which attribute values from other users will be merged.
In case multiple users have a value for the same attribute, the value will be taken first from the user to whom the values are to be merged, and then from the user with the lowest ID value.
The contacts in users_list are deleted after the merge: their IDs return 404 from then on.
Attributes
Optional unless marked required
- parent
- User to which attributes will be merged
- users_list
- List of users whose attribute values will be merged to the user given as "parent"
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/users/merge/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"parent": 1925,
"users_list": [
1926
]
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/users/merge/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
parent: 1925,
users_list: [
1926,
],
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/users/merge/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"parent" => 1925,
"users_list" => [
1926,
],
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/users/merge/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"parent": 1925,
"users_list": [
1926,
],
},
)
print(response.json())
Response examples
- 200 OK
- 400 Bad Request
{
"success": true
}
{"users_list": ["This field is required."],"parent": ["This field is required."]}A 400 lists every field that failed, each with its messages. Besides a missing field, you can get:
| Field | Message | When |
|---|---|---|
parent | Client User with user_id 123 does not exist | No contact has that ID. |
users_list | Users with these IDs do not exist in the application: [456]. | One of the IDs isn't a contact, including a contact already merged (merging deletes it). |
users_list | Ensure this field has at least 1 elements. | The list is empty. |
Response fields
Fields returned in the 200 OK response body.
- success
truewhen the contacts were merged.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.