Authentication

How to get up and running so that you can create your first Task.

Calling the Rightbrain API via OAuth 2.0 (Client Credentials Grant)

Prerequisites:

  • You have created an API client from the Rightbrain dashboard and have your Client ID and Client Secret.

Steps to Call the API:

  1. Obtain an Access Token:

    • To access the API, you first need to obtain an OAuth 2.0 access token. You will use your Client ID and Client Secret to request this token from the Rightbrain token endpoint.

    • Token Endpoint URL: The token URL is shown in the API client details page.

    • Request Details:

      • Method: POST
      • Headers:
        • Content-Type: application/x-www-form-urlencoded
      • Body (Form Data):
        • grant_type: client_credentials
        • client_id: <YOUR_CLIENT_ID> (Replace with your actual Client ID)
        • client_secret: <YOUR_CLIENT_SECRET> (Replace with your actual Client Secret)
    • Example Request (using curl):

      $curl -X POST \
      > -H "Content-Type: application/x-www-form-urlencoded" \
      > -d "grant_type=client_credentials&client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>" \
      > <TOKEN_ENDPOINT_URL>
    • Example Request (Python using requests library):

      1import requests
      2
      3token_endpoint = "<TOKEN_ENDPOINT_URL>" # Replace with the token endpoint
      4client_id = "<YOUR_CLIENT_ID>" # Replace with your Client ID
      5client_secret = "<YOUR_CLIENT_SECRET>" # Replace with your Client Secret
      6
      7data = {
      8 "grant_type": "client_credentials",
      9 "client_id": client_id,
      10 "client_secret": client_secret,
      11}
      12
      13response = requests.post(token_endpoint, data=data)
      14response.raise_for_status() # Raise an exception for bad status codes
      15access_token_data = response.json()
      16access_token = access_token_data["access_token"]
      17
      18print(f"Access Token: {access_token}")
    • Successful Response: A successful token request will return a JSON response containing the access_token, token_type (usually “bearer”), and expires_in (token expiration time in seconds).

  2. Call the API with the Access Token:

    • Once you have the access token, you can include it in the Authorization header of your API requests.

    • API Request Headers:

      • Authorization: Bearer <YOUR_ACCESS_TOKEN> (Replace <YOUR_ACCESS_TOKEN> with the access token obtained in the previous step)
    • Example API Call (using curl to fetch a list of Tasks - example endpoint):

      $curl -X GET \
      > -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
      > <API_ENDPOINT_URL>
    • Example API Call (Python using requests library - fetching a list of Tasks):

      1import requests
      2
      3api_endpoint = "<API_ENDPOINT_URL>" # Replace with your API endpoint
      4access_token = "<YOUR_ACCESS_TOKEN>" # Replace with your access token
      5
      6headers = {
      7 "Authorization": f"Bearer {access_token}"
      8}
      9
      10response = requests.get(api_endpoint, headers=headers)
      11response.raise_for_status()
      12api_data = response.json()
      13
      14print(f"API Response: {api_data}")
  3. Handle Token Expiration:

    • Access tokens have a limited lifespan (indicated by expires_in). Your application should handle token expiration and refresh the token when necessary. You can re-request a new access token using the same Client Credentials flow. Consider implementing token caching and refresh logic in your application.

By following these steps, you can successfully authenticate and call the Rightbrain API using OAuth 2.0 Client Credentials grant. Remember to consult the specific API endpoint documentation for request parameters, response formats, and any endpoint-specific authorization requirements.

Built with