> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withbenji.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Link User

> Endpoint to link a partner user with a merchant user

> [!NOTE]
>
> The `x-api-key` header value to be used on this API is your **partner API key**, which can be generated through the dashboard.

This endpoint allows you to link a partner user with a merchant user in the Benji platform. This is essential for enabling reward transactions between the partner and merchant systems.

### Request Body

**partner** `object` *required*

Partner user information

**properties**

**partner\_id** `string` *required*

The unique identifier of the partner in the Benji platform

**user\_external\_id** `string` *required*

The external user identifier from the partner's system

**merchant** `object` *required*

Merchant user information

**properties**

**merchant\_id** `string` *required*

The unique identifier of the merchant in the Benji platform

**user\_external\_id** `string`

The external user identifier from the merchant's system. If not present, Benji assumes this is an anonymous user.

### Return values

**code** `string`

Status code indicating the result of the operation

**message** `string`

Human-readable message describing the result

**data** `object`

Response data containing the link information

**properties**

**link\_id** `string`

The unique identifier for the created user link

**partner\_user\_id** `string`

The Benji platform user ID for the partner user

**merchant\_user\_id** `string`

The Benji platform user ID for the merchant user (null for anonymous users)

**created\_date** `datetime`

The timestamp when the link was created

```json Request with identified merchant user theme={null}
{
  "partner": {
    "partner_id": "partner_123",
    "user_external_id": "user_456"
  },
  "merchant": {
    "merchant_id": "merchant_789",
    "user_external_id": "customer_101"
  }
}
```

```json Request with anonymous merchant user theme={null}
{
  "partner": {
    "partner_id": "partner_123",
    "user_external_id": "user_456"
  },
  "merchant": {
    "merchant_id": "merchant_789"
  }
}
```

```json 200 Success - Identified User theme={null}
{
  "code": "ok",
  "data": {
    "link_id": "link_abc123",
    "partner_user_id": "benji_user_456",
    "merchant_user_id": "benji_merchant_user_101",
    "created_date": "2024-09-25T10:30:00.000Z"
  }
}
```

```json 200 Success - Anonymous User theme={null}
{
  "code": "ok",
  "data": {
    "link_id": "link_def456",
    "partner_user_id": "benji_user_456",
    "merchant_user_id": null,
    "created_date": "2024-09-25T10:30:00.000Z"
  }
}
```

```json 400 Bad Request theme={null}
{
  "error": "invalid_request",
  "message": "Missing required field: partner.partner_id"
}
```

```json 401 Unauthorized theme={null}
{
  "error": "unauthorized_request",
  "message": "Token is not authorized to make this request"
}
```

```json 404 Not Found theme={null}
{
  "error": "partner_not_found",
  "message": "The specified partner does not exist"
}
```

```json 409 Conflict theme={null}
{
  "error": "link_already_exists",
  "message": "A link between these users already exists"
}
```

> [!TIP]
>
> **Anonymous Users**: When `merchant.user_external_id` is not provided, Benji treats this as an anonymous user. This is useful for scenarios where you want to track partner user activity without requiring merchant user identification.

> [!NOTE]
>
> This endpoint establishes the connection required for reward transactions to flow between partner and merchant systems. Make sure both the partner and merchant are properly configured in your Benji account before calling this endpoint.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.