#
Authorization
To make the API easier to use, we recommend creating a few fixed parameters that you will use frequently.
OSAI_URL = 'https://app-eu.onestepai.com/api' # or 'https://app-us.onestepai.com/api'
API_TOKEN = 'OUR ACCESS TOKEN GENERATED IN OSAI'
HEADERS = {"Authorization": None}
To use the OnestepAI API, user authorization is required. This is done using an access token generated on the OSAI website in the settings tab.
The generated token is displayed only once, so make sure you copy it, because once you close the window, you will not be able to see it again.
If you lose your old token or your data is leaked, you can always delete your existing tokens and create many more.
def sign_in():
response = requests.get(
url=f'{OSAI_URL}/Users/SignIn', params={"token": API_TOKEN})
return response
Using the token, sign in to the API via /Users/SignIn
, the string received is the JWT authorization token that should be in every request.
token = sign_in()
global HEADERS
HEADERS = {"Authorization": token.text}
For easier use, we recommend assigning the JWT token to a global variable.
#
Get user information
To check the validity of the code and API connection, we recommend downloading the users' information and see if you get the correct data.
def get_user_info():
response = requests.get(url=f'{OSAI_URL}/Users', headers=HEADERS)
return response.json()
print("-------User info-------")
user_info = get_user_info()
print_formatted_json(user_info)
#
Example
import requests
import json
OSAI_URL = 'https://app-eu.onestepai.com/api'
API_TOKEN = 'OUR ACCESS TOKEN GENERATED IN OSAI'
HEADERS = {"Authorization": None}
def main():
token = sign_in()
global HEADERS
HEADERS = {"Authorization": token.text}
print("-------User info-------")
user_info = get_user_info()
print_formatted_json(user_info)
def sign_in():
response = requests.get(
url=f'{OSAI_URL}/Users/SignIn', params={"token": API_TOKEN})
return response
def get_user_info():
response = requests.get(
url=f'{OSAI_URL}/Users', headers=HEADERS)
return response.json()
def print_formatted_json(text):
print(json.dumps(text, indent=4))
if __name__ == '__main__':
main()
-------User info-------
{
"id":
"Guid-Guid-Guid-Guid",
"userName": "OneStep AI",
"name": "OneStep",
"surname": "AI",
"email": "onestepai@email.com",
"picture": "Link-To-Picture",
"bucket": "s3",
"colorMode": 1,
"enableTutorial": false
}