# API Integration

{% hint style="info" %}
This feature is available in the **Premium plan and higher**.
{% endhint %}

For more detailed API integration documentation, we recommend visiting the [Postman Documentation](https://documenter.getpostman.com/view/29070402/2sA3sAiTwM) or downloading the collection and importing it into Postman.

## Obtaining API token

[Log in to the GoodAccess **Control Panel**, and go to **Settings** > **API Integration**.](https://app.goodaccess.com/api-integration/)

Here, add a new integration or edit an existing one.

Select scopes of the integration, set expiration and allowed IP addresses, and generate a token.

Additionally, you can monitor the activity and communication of the integration from this interface.

<figure><img src="https://418253935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiJ406Lpi9EKoWDi7GFL7%2Fuploads%2FMwYh6Iwl66ogCctQP3KS%2FFeatures_API_Integration_01.png?alt=media&#x26;token=f9c50e19-ec05-4e34-8030-e95146057337" alt="API Integration detail."><figcaption><p>API Integration detail</p></figcaption></figure>

{% hint style="danger" %}
**Please note:** Immediately after being generated, you will see the token for a **limited period**. It is important to save the token in a secure place, as it provides access to the API and can be used to perform operations. After this period has expired, the token will be secured and you won’t be able to access it.
{% endhint %}

Your token can be used to authorize HTTP requests to the GoodAccess API. Each request must include an Authorization header with the token written as Bearer \<token>.

See the examples at the bottom of the page for correct syntax.

{% hint style="info" %}
Treat your token like a password and store it securely. For example, use the methods env and dotenv to store it in a development environment.
{% endhint %}

## Testing connection to GoodAccess API

To test your API connection, send an authenticated request to the test-connection endpoint. If the connection is successful, you will get a 200 return code.

## GET /api/v1/test-connection

> Test Connection

```json
{"openapi":"3.0.0","info":{"title":"GoodAccess Customer","version":"1.0.0"},"tags":[{"name":"Integrations"}],"servers":[{"url":"https://integration.goodaccess.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/api/v1/test-connection":{"get":{"tags":["Integrations"],"summary":"Test Connection","responses":{"200":{"description":"OK","headers":{"Content-Type":{"schema":{"type":"string"}}},"content":{"application/json":{"schema":{"type":"object"}}}}}}}}}
```

Below are examples of how to call the test endpoint in various languages.

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

```bash
curl -i https://integration.goodaccess.com/api/v1/test-connection \
  -H "Authorization: Bearer <integration_token>"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://integration.goodaccess.com/api/v1/test-connection'
headers = {
    'Authorization': 'Bearer <integration_token>'
}

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

{% endtab %}

{% tab title="Node" %}

```javascript
const axios = require('axios');

const url = 'https://integration.goodaccess.com/api/v1/test-connection';
const token = '<integration_token>';

axios.get(url, {
  headers: {
    'Authorization': `Bearer ${token}`
  }
})
.then(response => {
 //...
})
.catch(error => {
  //...
});
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = 'https://integration.goodaccess.com/api/v1/test-connection';
$token = '<integration_token>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $token,
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);
```

{% endtab %}
{% endtabs %}

## [API Reference](https://support.goodaccess.com/configuration-guides/features/api-integration/api-reference)
