# Get Buyer Key

- Sandbox: `POST https://sandbox.payme.io/api/get-buyer-key`
- Production: `POST https://live.payme.io/api/get-buyer-key`

## Credentials

- Request body field `seller_payme_id` (required): Our unique seller ID.

## Overview

This API endpoint will allow you to get the buyer-key created and used to pay for a certain payment request in our system. 

#### Use Case for Israeli Direct Debit
Once a new authorization request is created and the buyer is approved, a new buyer key is generated behind the scenes and can be obtained using this API endpoint.

## Parameters

This endpoint takes no path, query or header parameters.

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `payme_sale_id` | string | yes | Our unique sale ID. |
| `seller_payme_id` | string | yes | Our unique seller ID. |

### Request example

```json
{
  "payme_sale_id": "SALE1686-XXXXXXXX-XXXXXXXX-XXXXXXXX",
  "seller_payme_id": "MPL16852-XXXXXXXX-XXXXXXXX-XXXXXXXX"
}
```

## Code samples

### curl

```bash
curl -X POST 'https://sandbox.payme.io/api/get-buyer-key' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "payme_sale_id": "SALE1686-XXXXXXXX-XXXXXXXX-XXXXXXXX",
  "seller_payme_id": "MPL16852-XXXXXXXX-XXXXXXXX-XXXXXXXX"
}'
```

### Node.js

```javascript
const response = await fetch("https://sandbox.payme.io/api/get-buyer-key", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "payme_sale_id": "SALE1686-XXXXXXXX-XXXXXXXX-XXXXXXXX",
    "seller_payme_id": "MPL16852-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  }),
});

console.log(await response.text());
```

### Python

```python
import requests

response = requests.post(
    "https://sandbox.payme.io/api/get-buyer-key",
    json={
        "payme_sale_id": "SALE1686-XXXXXXXX-XXXXXXXX-XXXXXXXX",
        "seller_payme_id": "MPL16852-XXXXXXXX-XXXXXXXX-XXXXXXXX",
    },
)

print(response.text)
```

### PHP

```php
<?php

$body = <<<'BODY'
{
  "payme_sale_id": "SALE1686-XXXXXXXX-XXXXXXXX-XXXXXXXX",
  "seller_payme_id": "MPL16852-XXXXXXXX-XXXXXXXX-XXXXXXXX"
}
BODY;

$ch = curl_init('https://sandbox.payme.io/api/get-buyer-key');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
```

## Responses

### 200 — OK (success)

| Field | Type | Description |
| --- | --- | --- |
| `payme_sale_id` | string | Our unique sale ID. |
| `buyer_key` | string | Buyer's unique token. |
| `buyer_card_mask` | string | Buyer's card mask. |
| `buyer_card_expiry` | string | Buyer's card exp (MMYY). |
| `buyer_card_brand` | string | Buyer's card brand. |
| `status_code` | string |  |

```json
{
  "payme_sale_id": "MPL16861-35251ZB5-PLVPEMCW-ZUAQJBQO",
  "buyer_key": "BUYER166-5640185F-UFEKYAYD-WLJSO6QS",
  "buyer_card_mask": "532610******5846",
  "buyer_card_expiry": "0426",
  "buyer_card_brand": "099474924",
  "buyer_is_permanent": null,
  "status_code": null
}
```

### 600 (error)

| Field | Type | Description |
| --- | --- | --- |
| `status_code` | integer |  |
| `status_error_details` | string |  |
| `status_additional_info` | string |  |
| `status_error_code` | integer |  |
| `session` | string |  |

```json
{
  "status_code": 1,
  "status_error_details": "Buyer not found",
  "status_additional_info": "No Buyer for Sale",
  "status_error_code": 600,
  "session": "St4K2Azk"
}
```
