🔑 Authentication
To obtain a new API key and secret pair:
Request:
GET /api/v1/api_credentials
Cookies: SESSION=<session from authenticated user browser session>
In simpler words:
log into https://app.visual-layer.com/
then navigate to https://app.visual-layer.com/api/v1/api_credentials
Example Response:
curl -b SESSION=<session from authenticated user browser session>
https://app.visual-layer.com/api/v1/api_credentials
{
"api_key": "<api_key>",
"api_secret": "<api_secret>",
"message": "API key created. Write down the secret - it's only shown once!"
}
Generate JWT Token for Authentication
Generate a JWT from the API key/secret and use it for subsequent API calls by
passing it in the authorization header (see examples below for more details). The
following python code snippet shows an example of creating a JWT with 10
minute expiration:
import jwt
from datetime import datetime, timezone, timedelta
def generate_jwt(api_key: str, api_secret: str):
jwt_algorithm = "HS256"
jwt_header = {
'alg': jwt_algorithm,
'typ': 'JWT',
'kid': api_key,
}
payload = {
'sub': api_key,
'iat': datetime.now(tz=timezone.utc),
'exp': datetime.now(tz=timezone.utc) + timedelta(minutes=10),
'iss': 'sdk'
}
return jwt.encode(payload=payload, key=api_secret, algorithm=jwt_algorithm, headers=jwt_header)
Updated 7 days ago