Skip to main content

Your first request

This lists the products your app can see.

# 1. Get a token
TOKEN=$(curl -s -X POST https://api.staging.agantia.com/api/public/v1/oauth/token \
-u "$AGANTIA_CLIENT_ID:$AGANTIA_CLIENT_SECRET" \
-d grant_type=client_credentials | jq -r .access_token)

# 2. List products
curl -s "https://api.staging.agantia.com/api/public/v1/products?per_page=5&fields=title,slug,from_price" \
-H "Authorization: Bearer $TOKEN" | jq
{
"data": [
{
"id": 156,
"title": "Desert Safari with BBQ Dinner",
"slug": "desert-safari-bbq",
"from_price": { "amount": "250.00", "currency": "AED" }
}
],
"meta": { "page": 1, "per_page": 5, "total": 52, "total_pages": 11 },
"links": {
"self": "/api/public/v1/products?per_page=5&fields=title%2Cslug%2Cfrom_price&page=1",
"next": "/api/public/v1/products?per_page=5&fields=title%2Cslug%2Cfrom_price&page=2"
}
}

Node.js​

const base = 'https://api.staging.agantia.com/api/public/v1';

async function getToken() {
const response = await fetch(`${base}/oauth/token`, {
method: 'POST',
headers: {
Authorization: 'Basic ' + Buffer.from(`${process.env.AGANTIA_CLIENT_ID}:${process.env.AGANTIA_CLIENT_SECRET}`).toString('base64'),
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'grant_type=client_credentials',
});
if (!response.ok) throw new Error(`token ${response.status}`);
return (await response.json()).access_token;
}

const token = await getToken();
const products = await fetch(`${base}/products?per_page=5`, {
headers: { Authorization: `Bearer ${token}` },
}).then((r) => r.json());
console.log(products.data.map((p) => p.title));

Python​

import os, requests

base = "https://api.staging.agantia.com/api/public/v1"
token = requests.post(
f"{base}/oauth/token",
auth=(os.environ["AGANTIA_CLIENT_ID"], os.environ["AGANTIA_CLIENT_SECRET"]),
data={"grant_type": "client_credentials"},
).json()["access_token"]

products = requests.get(f"{base}/products", params={"per_page": 5},
headers={"Authorization": f"Bearer {token}"}).json()
print([p["title"] for p in products["data"]])

If it does not work​

  • 401 invalid-token: the token expired, or you sent a sandbox token to production (or the reverse).
  • 403 insufficient-scope: the app lacks the permission. Ask the merchant to grant it on the Permissions tab.
  • An empty list: the app may not have any catalogue selected. Ask the merchant to check Data Access > Effective access.