Skip to main content
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 '
{
  "payload": {
    "userId": "64ef3c29f9a1c27e1b2c3a4d",
    "userToLinkId": "64ef3c29f9a1c27e1b2c3a99"
  }
}
'
{
  "message": "<string>",
  "data": {
    "updatedPrimaryUser": {
      "emails": [
        "[email protected]"
      ],
      "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

NameTypeRequiredDescription
AuthorizationstringYesBearer token
Content-TypestringYesapplication/json

Request Body

{
  "payload": {
    "userId": "64b7f1a2e4b0a5d3f9c12345",
    "userToLinkId": "64b7f2b3e4b0a5d3f9c54321"
  }
}

Request Body Schema

FieldTypeRequiredDescription
payloadobjectYesLink accounts payload
payload.userIdstringYesPrimary user ID (will keep the account)
payload.userToLinkIdstringYesSecondary user ID (will be deleted)

Response

200 OK - Successfully linked accounts

{
  "message": "Accounts linked successfully",
  "data": {
    "updatedPrimaryUser": {
      "_id": "64b7f1a2e4b0a5d3f9c12345",
      "emails": "[email protected]",
      "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

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
payload
object

Response

Successfully linked accounts

message
string
data
object