# Authentication

The My Buggy My Car API uses Basic authentication and utilises your Subscription ID as a username equivalent and API Key as a password equivalent. The client should send an HTTP request with the `Authorization` header that contains the word Basic followed by a space and a base64-encoded string subscription\_id:api\_key. For example, to authorise as `demo : p@55w0rd` the client would send

`Authorization: Basic ZGVtbzpwQDU1d29yZA==`

If you're not familiar with generating a base64-encoded string, we can recommend the use of website <https://www.base64encode.org>.&#x20;

{% hint style="info" %}
Note If you are generating your encoded string with linux, please ensure to include the -n flag to remove any surplus/hidden characters e.g. `echo -n 'demo:p@55w0rd' | base64`
{% endhint %}

The My Buggy My Car API requires the `Authorization` header is sent with all API requests to the server or a 403 error will be returned.

&#x20;You must replace `ZGVtbzpwQDU1d29yZA==` with your personal Base64 encoded Subscription ID and API Key.

> To authorise, you're welcome to use this sample code:

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

```php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();

$request->setUrl('https://api.mybuggymycar.com/API_ENDPOINT_HERE');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Authorization' => 'Basic YOUR_BASE64_KEY'
));
```

{% endtab %}

{% tab title="Python" %}

```python
import http.client

conn = http.client.HTTPSConnection("api.mybuggymycar.com")

headers = { 'authorization': "Basic YOUR_BASE64_KEY" }

conn.request("GET", "API_ENDPOINT_HERE", headers=headers) you cpass the correct header 
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl  --location --request GET 'API_ENDPOINT_HERE'
  --header 'authorization: Basic YOUR_BASE64_KEY'
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.mybuggymycar.com/API_ENDPOINT_HERE");
xhr.setRequestHeader("authorization", "Basic YOUR_BASE64_KEY");

xhr.send(data);
```

{% endtab %}
{% endtabs %}

> Make sure to replace `API_ENDPOINT_HERE` with the appropriate query and `YOUR_BASE64_KEY` with your API key.
