Back to General Forum

Forum Topic: Getting Started with the New API

Category: General Replies: 42 Views: 1.2k
Last Post: 2 hours ago

Hi everyone,

I'm trying to integrate the new API for our service, but I'm running into a bit of a roadblock with the authentication process. The documentation mentions OAuth2, but the examples seem a bit outdated. Has anyone had success recently with setting up authentication? Specifically, I'm struggling with getting a valid access token.

Any pointers or examples would be greatly appreciated!

Hey John,

I went through the same thing last week! The key is to use the `/v2/auth/token` endpoint with the `client_credentials` grant type. Make sure your `client_id` and `client_secret` are correctly formatted in the request body. I had an issue with whitespace in my secret initially.

Here's a quick snippet in Python:


import requests

url = "https://api.example.com/v2/auth/token"
payload = {
    "grant_type": "client_credentials",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET"
}
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}

response = requests.post(url, data=payload, headers=headers)
if response.status_code == 200:
    token_data = response.json()
    access_token = token_data["access_token"]
    print("Successfully obtained access token:", access_token)
else:
    print("Error obtaining token:", response.text)
                

Let me know if that helps!

Great advice, Alice! I'll try that out. Also, has anyone figured out how to handle rate limiting effectively? I'm hitting the limits quite often when making bulk requests.

Leave a Reply