API Access Guide

OAuth2 and Client Credentials Flow

We employ OAuth2's Client Credentials Flow for server-to-server communication. You'll authenticate your client through its ID and secret, and in return, you'll receive an access token which will authorize your requests to our server.

Security Considerations

The security of the client credentials is your responsibility. Treat them with the same security measures as you would with sensitive data like usernames and passwords. Avoid exposing them in client-side code or sharing with unauthorized entities.

Requesting Client Credentials

To obtain your unique client_id and client_secret, send a request to support@nilajune.com.

1) Request an Access Token

Use the client_id and client_secret to send a POST request to our token endpoint and retrieve your access token.

Python:


    import requests

    # Endpoint to obtain access token
    token_endpoint = 'https://auth.nilajuneapi.com/oauth2/token'
    
    # Parameters required for token endpoint request
    token_request_data = {
        'grant_type':    'client_credentials',
        'client_id':     'your_client_id',
        'client_secret': 'your_client_id_secret',
    }
    
    # Send POST request to token endpoint to obtain access token
    response = requests.post(token_endpoint, data=token_request_data)

cURL:


    curl -X POST https://auth.nilajuneapi.com/oauth2/token \
    -d 'client_id=your_client_id' \
    -d 'client_secret=your_client_secret' \
    -d 'grant_type=client_credentials'

2) Extract an Access Token from response

Python:


    # Extract access token from response
    access_token = response.json()['access_token']

3) Request payload via the API with the Token

The access token can be used to authorize requests to our API. Include it in the Authorization header of your requests. In order to retrieve the narrative append the parmeter surveyId to the end of the URL.

Python:


    ENDPOINT = 'https://api.nilajuneapi.com/nlg_ReadSurveySecured?surveyId={survey_ID}' 
    # Headers for request
    headers = { 'Authorization': '{access_token}'}
    # Make GET request to Lambda function
    response = requests.get(LAMBDA_ENDPOINT, headers=headers)

cURL:


    curl -X GET https://api.nilajuneapi.com/nlg_ReadSurveySecured?surveyId={survey_ID} \
    -H 'Authorization: {access_token}'

Support

For any issues encountered during the process, reach out to us at support@nilajune.com.