Get started
Authenticate with an API key
Create an API key, limit it to some sites, choose whether it can make changes, and revoke it when you're done.
Every request needs an API key. A key acts for the person who made it, on one team, so it reads what that person can read in Onsite.
Before you start
Section titled “Before you start”- A team with an active Onsite plan.
- Any role on the team can make keys. A key can never do more than its maker’s role allows, so a viewer’s key reads but can’t change anything.
Create a key
Section titled “Create a key”Open API keys
In Onsite, go to Settings › API keys and select Create key.
Name it
Name it after where it will run, such as “Looker Studio” or “Weekly report script”, so you know which one to revoke later.
Choose its sites
Leave All sites on to read every site you can, including sites added later. Or pick the sites it may read: it can’t see any other site, and it can’t read portfolios.
Choose whether it can make changes
Keys only read unless you turn on Can make changes. Turn it on for a key that tracks keywords, updates alerts, adds notes or starts exports.
Copy the key
Onsite shows the key once. Copy it and store it somewhere safe, like your password manager or your platform’s secret settings. If you lose it, revoke it and create another.
Keys start with oapi_ and last one year. Settings › API keys shows when each one expires and when it was last used.
Send the key
Section titled “Send the key”Put the key in the Authorization header of every request, after Bearer:
curl "https://api.onsite.so/api/v1/sites" \ -H "Authorization: Bearer $ONSITE_API_KEY"const response = await fetch("https://api.onsite.so/api/v1/sites", { headers: { Authorization: `Bearer ${process.env.ONSITE_API_KEY}` },});const { sites } = await response.json();import osimport requests
response = requests.get( "https://api.onsite.so/api/v1/sites", headers={"Authorization": f"Bearer {os.environ['ONSITE_API_KEY']}"},)sites = response.json()["sites"]What a key can do
Section titled “What a key can do”| Key | Reads | Makes changes |
|---|---|---|
| All sites | Every site its maker can read, and portfolios | Only with Can make changes |
| Some sites | Only the sites picked when it was made | Only with Can make changes, on those sites |
A key also follows its maker’s role. If their role can’t do something in Onsite, the key can’t do it either.
Revoke a key
Section titled “Revoke a key”In Settings › API keys, select Revoke next to the key. It stops working at once: the next request with it gets a 401.
A key also stops working when it expires, and when the person who made it leaves the team.
If something goes wrong
Section titled “If something goes wrong”401 unauthenticated
The key is missing, mistyped, revoked or expired. Check that the header reads Authorization: Bearer oapi_... with no quotes or spaces inside the key. If the key was revoked or expired, create a new one.
403 This key can only read
The request makes a change, and the key doesn’t have Can make changes. Create a key with it turned on. A key’s settings can’t be changed after it’s made.
403 This key is limited to some sites
Portfolios read every site on the team, so they need a key for all sites.
404 This key can't read a site
The site isn’t one of the key’s sites, or the name doesn’t match one. error.didYouMean suggests the closest site the key can read.
402 payment_required
The team’s plan has ended. An owner can renew it in Settings › Billing.