Docs menu
Authentication
Send the key in the api-key header.
The SDK is not released. What follows uses plain HTTP.
The route optimisation group takes an API key in the api-key header and never a Bearer token. The key has to be valid and entitled, and the feature has to be switched on server side.
const BASE = "https://<your-host>/api/v1/partners";
// Route optimisation authenticates with the api-key header, lowercase.
// It is not a Bearer token. The other groups take Authorization: Bearer
// with a JWT, and tour planning accepts either.
const headers = { "api-key": process.env.ROUTE4GREEN_API_KEY! };
// The cheapest request that proves a key works end to end: list your own
// jobs. Three things must be true at once for it to answer: the key is
// valid and not expired, the key has been granted Route optimization
// access by the Route4Green team, and the feature is switched on server
// side. If any one is false the request is refused with a code from the
// error tables in the reference.
// Paginated: page (default 1) and size (default 10, max 100) narrow the
// list, and status filters by job status.
const response = await fetch(`${BASE}/addons/route-optimization/jobs?page=1&size=10`, { headers });
// Branch on the envelope's success flag first, never on response.ok
// alone: some failures arrive as HTTP 200 with success false.
const envelope = await response.json();
if (!envelope.success) {
// error_code is a string on some responses and a number on others.
throw new Error(`${String(envelope.error_code)}: ${envelope.message}`);
}
console.log("key is live; jobs visible:", envelope.data);The full explanation, including how to get a key, is in the authentication section on the documentation index.