Skip to main content
Making REST Requests

Using a Personal Access Token to make HTTP requests

Updated this week

Introduction

Kodexa's API allows you to interact with the platform programmatically using REST requests. To authenticate these requests, you can use your Personal Access Token (PAT) in the request header. This article will guide you through the process of making authenticated REST requests to Kodexa's API using your PAT.

Setting Up Your Request

1. Obtain Your PAT

Before making any requests, ensure you have generated a Personal Access Token as described in the previous article on creating PATs in Kodexa.

2. Prepare Your Request

When making a REST request to Kodexa's API, you'll need to include your PAT in the request header. The specific header to use is:

x-access-token: YOUR_PERSONAL_ACCESS_TOKEN

Replace YOUR_PERSONAL_ACCESS_TOKEN with the actual token you generated.

Making REST Requests:

1. Using cURL:

If you're using cURL to make requests, you can include the header like this:

curl -H "x-access-token: YOUR_PERSONAL_ACCESS_TOKEN" https://api.kodexa.com/v1/endpoint

2. Using Python with requests library:

If you're using Python, you can use the requests library to make API calls:

import requests

headers = {
'x-access-token': 'YOUR_PERSONAL_ACCESS_TOKEN'
}

response = requests.get('https://api.kodexa.com/v1/endpoint', headers=headers)

3. Using JavaScript with fetch:

For JavaScript applications, you can use the fetch API:


fetch('https://api.kodexa.com/v1/endpoint', {
headers: {
'x-access-token': 'YOUR_PERSONAL_ACCESS_TOKEN'
}
})
.then(response => response.json())
.then(data => console.log(data));

Best Practices

1. Keep Your Token Secure: Never expose your PAT in client-side code or public repositories.

2. Use Environment Variables: Store your PAT in environment variables rather than hardcoding it in your scripts.

3. Set Appropriate Permissions: Ensure your PAT has only the necessary permissions for the operations you're performing.

4. Handle Errors: Always include error handling in your requests to manage cases where the token might be invalid or expired.

Conclusion

By including your Personal Access Token in the x-access-token header of your REST requests, you can securely authenticate and interact with Kodexa's API. This method provides a simple yet powerful way to integrate Kodexa's capabilities into your applications and workflows. Remember to keep your token secure and follow best practices to ensure the integrity of your interactions with the Kodexa platform.

Did this answer your question?