> For the complete documentation index, see [llms.txt](https://doc.blowhorn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.blowhorn.com/api-docs/authentication/partner-authentication.md).

# Partner Authentication

Authentication APIs for partners

API authentications are performed by using the API key. All partners need to use below authentication API to get the API key which they can use for accessing other api services from Blowhorn.

## Partner Authentication

<mark style="color:green;">`POST`</mark> `/orders/customer/authtoken`

This api takes base64 encoded username and password to authenticate the partner and returns the partner API key. Post authentication Partners should be able to authenticate and use Blowhorn APIs  by just passing API key each time in the header.

#### Request Body

| Name                                       | Type   | Description                    |
| ------------------------------------------ | ------ | ------------------------------ |
| username<mark style="color:red;">\*</mark> | String | Base64 encoded username string |
| password                                   | String | Base64 encoded password string |

{% tabs %}
{% tab title="200: OK After successful authentication" %}

```javascript
{
    "status": "PASS",
    "api_key": "Bj143Lm09qjQ"
}
```

{% endtab %}

{% tab title="400: Bad Request Bad Request/Validation Error" %}

```javascript
{
    "status": "FAIL",
    "message": "Sample Error Message"
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Example/Schema" %}

```json
{
    "email": "test@xyz.com",
    "password": "1234"
}
```

{% endtab %}
{% endtabs %}

#### Base64 Encoding

{% tabs %}
{% tab title="Python" %}

```python
import base64
import requests

auth_string = "email:password"
auth_string_bytes = auth_string.encode('ascii')

base64_bytes  = base64.b64encode(auth_string_bytes)
base64_string = base64_bytes.decode('ascii')

url = 'https://blowhorn.com/api/customer/auth'
headers = {'Authorization': base64_string}

response = requests.get(url, headers=headers)

api_key_string = response.json().get('api_key')
api_key_bytes  = api_key_string.encode('ascii')
b64_bytes      = base64.b64decode(api_key_bytes)
api_key        = b64_bytes.decode('ascii')
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
 $auth_str = "email:password";
 $base64_str = base64_encode($auth_str);
 
 $url = 'https://blowhorn.com/api/customer/auth';
 $ch = curl_init();
 curl_setopt($ch,CURLOPT_URL,$url);   
 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Authorization: ' . $base64_str)
  );
  $result = curl_exec($ch);
  
  $data = json_decode($result);
  $api_key_string = $data->api_key;
  $api_key = base64_decode($api_key_string);
  ?>
```

{% endtab %}
{% endtabs %}
