~/enine-sites-help/developers/how-to-make-your-first-api-request
How to make your first API request
List your sites with GET /api/v1/site/, then read one site's content by putting its domain in the path.
You need an API token. See How to get an API token.
Steps
- List your sites.
- Copy the domain of the site you want.
- Read that site's content, using the domain in the path.
1. List your sites
curl -H "Authorization: Token $ENINE_TOKEN" \
https://e9sites.com/api/v1/site/
[
{"domain": "mysite.e9sites.com", "name": "My Site"}
]
2. Read one site's content
curl -H "Authorization: Token $ENINE_TOKEN" \
https://e9sites.com/api/v1/site/mysite.e9sites.com/artifacts/
You should see
JSON for your sites, then JSON for the content of the site you named.
Good to know
The domain in the path must match the site's domain exactly. There are no aliases, and a domain that is not a site returns 404.
The same request in Python:
import os
import requests
headers = {"Authorization": f"Token {os.environ['ENINE_TOKEN']}"}
response = requests.get("https://e9sites.com/api/v1/site/", headers=headers)
print(response.json())
If something goes wrong
- 401: the token is missing, malformed, or deactivated. Check that the header says Token, not Bearer.
- 403: the token is valid, but your role on that site is not high enough.
- 404: the domain in the path is not a site you can see.
Next
- Next step: API basics: roles, requests, and errors