Skip to main content

01. Authenticate

How to authenticate with the Jinko API

In order to interact with the Jinko API, you'll first need to authenticate your application or script. Authentication is performed using an API key, which can be obtained through your Jinko account.

Authentication using API Key

You can authenticate by passing your API key as a header in the request. The following example shows how to authenticate using the make_request function provided by the jinko-sdk.

import jinko_helpers as jinko

# Set your API key
api_key = "your-api-key"

# Set the headers including the Authorization key
headers = {
"Authorization": f"Bearer {api_key}"
}

# Example request to authenticate
jinko.make_request(
path='/app/v1/auth/check',
method='GET',
options={'input_format': 'application/json'},
headers=headers
)

Storing the API Key Securely

For security reasons, it is recommended to avoid hardcoding your API key in your code. Instead, store it in an environment variable and retrieve it when needed:

import os
import jinko_helpers as jinko

# Load API key from environment variable
api_key = os.getenv("JINKO_API_KEY")

headers = {
"Authorization": f"Bearer {api_key}"
}

# Authenticate with Jinko API
jinko.make_request(
path='/app/v1/auth/check',
method='GET',
headers=headers
)