I’m currently working on some code that requires me to use Ayon’s REST api.
I’m using HTTPX
for my REST calls but using requests
works as well.
Initial login:
import httpx
payload = {"name": ayon_login_username, "password": ayon_login_password}
response = httpx.post(
f"{ayon_server_url}/api/auth/login",
json=payload,
)
token = response.json().get("token")
Get all projects:
headers = {}
headers[
"Authorization"
] = f"Bearer {token}"
response = httpx.get(
f"{ayon_server_url}/api/projects",
headers=headers,
)
print(response.json())
You can also use a UserEntity as the authentication of a REST call:
import httpx
from ayon_server.auth.session import Session
session = await Session.create(user)
headers = {}
headers["Authorization"] = f"Bearer {session.token}"
async with httpx.AsyncClient() as client:
response = await client.get(
f"{ayon_server_url}/api/projects",
headers=headers,
)
print(response.json())
Some good info I figured out on where to place your payload:
On post
the payload goes into json
(and needs to be a json string)
On patch
the payload goes into json
(and needs to be a json string)
On put
the payload goes into content