Link two user accounts
curl --request POST \
--url http://localhost:2000/user/link-accounts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "http://localhost:2000/user/link-accounts"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('http://localhost:2000/user/link-accounts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "2000",
CURLOPT_URL => "http://localhost:2000/user/link-accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:2000/user/link-accounts"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:2000/user/link-accounts")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:2000/user/link-accounts")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_body{
"message": "<string>",
"data": {
"updatedPrimaryUser": {
"emails": [
"user@example.com"
],
"personalInformation": {
"firstName": "John",
"lastName": "Doe"
},
"role": "employee",
"department": {
"id": "64ef3c29f9a1c27e1b2c3a4d",
"role": "manager"
},
"reportsTo": "64ef3c29f9a1c27e1b2c3a99",
"createdAt": "2025-09-12T08:30:00Z",
"config": {
"lastActive": "2025-09-12T09:15:00Z"
},
"linkedAccounts": {
"google": {
"meta": {
"email": "zain"
}
}
}
}
}
}User Administration
Link User Accounts
Admin-only endpoint to link a secondary user account into a primary account. - The userToLinkId account will be deleted after merging its linked accounts into the primary userId.
POST
/
user
/
link-accounts
Link two user accounts
curl --request POST \
--url http://localhost:2000/user/link-accounts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'import requests
url = "http://localhost:2000/user/link-accounts"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('http://localhost:2000/user/link-accounts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "2000",
CURLOPT_URL => "http://localhost:2000/user/link-accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:2000/user/link-accounts"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:2000/user/link-accounts")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:2000/user/link-accounts")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_body{
"message": "<string>",
"data": {
"updatedPrimaryUser": {
"emails": [
"user@example.com"
],
"personalInformation": {
"firstName": "John",
"lastName": "Doe"
},
"role": "employee",
"department": {
"id": "64ef3c29f9a1c27e1b2c3a4d",
"role": "manager"
},
"reportsTo": "64ef3c29f9a1c27e1b2c3a99",
"createdAt": "2025-09-12T08:30:00Z",
"config": {
"lastActive": "2025-09-12T09:15:00Z"
},
"linkedAccounts": {
"google": {
"meta": {
"email": "zain"
}
}
}
}
}
}Admin-only endpoint to link a secondary user account into a primary account. The
userToLinkId account will be deleted after merging its linked accounts into the primary userId.
Request
Headers
| Name | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer token |
| Content-Type | string | Yes | application/json |
Request Body
{
"payload": {
"userId": "64b7f1a2e4b0a5d3f9c12345",
"userToLinkId": "64b7f2b3e4b0a5d3f9c54321"
}
}
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
| payload | object | Yes | Link accounts payload |
| payload.userId | string | Yes | Primary user ID (will keep the account) |
| payload.userToLinkId | string | Yes | Secondary user ID (will be deleted) |
Response
200 OK - Successfully linked accounts
{
"message": "Accounts linked successfully",
"data": {
"updatedPrimaryUser": {
"_id": "64b7f1a2e4b0a5d3f9c12345",
"emails": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "user",
"linkedAccounts": [
{
"provider": "google",
"providerId": "123456789"
},
{
"provider": "microsoft",
"providerId": "987654321"
}
]
}
}
}
400 Bad Request
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid request body"
}
}
401 Unauthorized
{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing or invalid token or insufficient permissions"
}
}
404 Not Found
{
"error": {
"code": "USER_NOT_FOUND",
"message": "User not found"
}
}
500 Internal Server Error
{
"error": {
"code": "SERVER_ERROR",
"message": "Internal server error"
}
}
Example
curl -X POST 'http://localhost:2000/user/link-accounts' \
-H 'Authorization: Bearer your-jwt-token' \
-H 'Content-Type: application/json' \
-d '{
"payload": {
"userId": "64b7f1a2e4b0a5d3f9c12345",
"userToLinkId": "64b7f2b3e4b0a5d3f9c54321"
}
}'
Notes
- This is an admin-only endpoint - requires administrative privileges
- Both user IDs must be valid MongoDB ObjectIds
- The secondary account (
userToLinkId) will be permanently deleted - All linked accounts from the secondary user are merged into the primary
- This action is irreversible - the secondary account cannot be restored
- Use this to consolidate duplicate user accounts
- The primary user retains their original ID and all merged linked accounts
- Permissions and department assignments from the secondary account are lost
Was this page helpful?