API Authentication¶
Before sending requests to the GraphQL API, you must authenticate. You do this by obtaining a JWT from our /auth endpoint, using an API key.
Need an API key?
Users can obtain an API key from the Horizon3.ai Portal.
Authenticate¶
Below are examples for obtaining an authenticated JWT. Each example sends an HTTP request to the Horizon3.ai auth endpoint, which gets referenced via the environment variable H3_AUTH_URL:
export H3_AUTH_URL=https://api.gateway.horizon3ai.com/v1/auth
export H3_AUTH_URL=https://api.gateway.horizon3ai.eu/v1/auth
Store¶
Before proceeding, store your API key in environment variable H3_API_KEY:
export H3_API_KEY=<your-api-key>
curl -X POST \
-H "Content-Type: application/json" \
-d '{"key": "'"$H3_API_KEY"'"}' \
$H3_AUTH_URL
import os
import requests
url = os.environ["H3_AUTH_URL"]
response = requests.post(url, json={"key": os.environ["H3_API_KEY"]})
result = response.json() if response.status_code == 200 else None
Send¶
You can use the resulting token to send authenticated requests to the GraphQL API.
{"token": "<your-api-token>"}
JWT expiration
Each JWT expires after one hour, at which point the /graphql endpoint will respond with the token expiration message shown below. If this occurs, obtain a new JWT by re-authenticating with the /auth endpoint.
{"message":"The incoming token has expired"}
Status codes¶
HTTP status codes returned by the /auth endpoint are summarized below.
| Code | Title | Description |
|---|---|---|
200 |
Success | Response contains the JWT. |
400 |
Bad Request | Malformed request, review the error message. |
401 |
Unauthorized | Not authenticated due to invalid API key. |
5xx |
Internal Server Error | An unexpected error was encountered. |