Skip to content

Token URL

MarsX gets an access token from your token URL before it reads your other endpoints. You build one endpoint that follows OAuth 2.0 client credentials (RFC 6749 section 4.4), and you issue MarsX one read-only client, the MarsX read client, for each connection and environment.

MarsX signs in with HTTP Basic client authentication. The scope is leads:read. It is read-only.

Request
POST <your token URL>
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <base64(client_id:client_secret)>
grant_type=client_credentials&scope=leads:read
Response
{
"access_token": "example-access-token",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "leads:read"
}

The response follows the PartnerTokenResponse schema in the contract. access_token, token_type (Bearer) and expires_in are required. scope is optional. MarsX ignores any other member.

Field Rule
expires_in Between 300 and 86,400 seconds. 3600 is a good value
Renewal MarsX asks for a new token 30 seconds before it expires
Scope Read-only. You name it

Every read call carries Authorization: Bearer <access_token>.

Case Your endpoint answers What MarsX does
Wrong or expired token 401 Asks for a new token once, then retries the read
Valid token without the scope 403 Does not retry by itself. It treats this as a contract failure

Errors follow RFC 6749 section 5.2. Answer with JSON that has an error member.

Case Status error
Unknown client or wrong secret 401 invalid_client
grant_type is not client_credentials 400 unsupported_grant_type
The scope is not one you offer 400 invalid_scope
Wrong content type or a missing parameter 400 invalid_request

Your developer enters the client ID and secret in Concour: Developers, then Your endpoints, in the fields Client ID and Client secret (the client has the scope leads:read). The secret is saved and never shown again. Leave the field empty on a later save to keep the saved secret. Never paste a secret into email or WhatsApp.

These examples show the shape of the answers. They keep tokens in memory and read the client from environment variables. Run them behind HTTPS, and keep tokens in a shared store if you run more than one server. Your read endpoints check an Authorization: Bearer header against the same store: a token that is unknown or past its expiry gets 401, and a valid token without the scope gets 403.

token-server.mjs
import { createServer } from "node:http";
import { randomBytes, timingSafeEqual } from "node:crypto";
const CLIENT_ID = process.env.MARSX_CLIENT_ID;
const CLIENT_SECRET = process.env.MARSX_CLIENT_SECRET;
const SCOPE = "leads:read";
const EXPIRES_IN = 3600;
const tokens = new Map(); // access_token -> expiry, in milliseconds since the epoch
const same = (a, b) => {
const x = Buffer.from(a);
const y = Buffer.from(b);
return x.length === y.length && timingSafeEqual(x, y);
};
function basicCredentials(req) {
const [scheme, encoded] = (req.headers.authorization ?? "").split(" ");
if (scheme !== "Basic" || !encoded) return null;
const text = Buffer.from(encoded, "base64").toString();
const i = text.indexOf(":");
return i < 0 ? null : [text.slice(0, i), text.slice(i + 1)];
}
function reply(res, status, body, headers = {}) {
res.writeHead(status, {
"content-type": "application/json",
"cache-control": "no-store",
pragma: "no-cache",
...headers,
});
res.end(JSON.stringify(body));
}
createServer(async (req, res) => {
const creds = basicCredentials(req);
if (!creds || !same(creds[0], CLIENT_ID) || !same(creds[1], CLIENT_SECRET)) {
return reply(res, 401, { error: "invalid_client" }, { "www-authenticate": "Basic" });
}
let raw = "";
for await (const chunk of req) raw += chunk;
const form = new URLSearchParams(raw);
const isForm = (req.headers["content-type"] ?? "").startsWith("application/x-www-form-urlencoded");
if (req.method !== "POST" || !isForm || !form.get("grant_type")) {
return reply(res, 400, { error: "invalid_request" });
}
if (form.get("grant_type") !== "client_credentials") {
return reply(res, 400, { error: "unsupported_grant_type" });
}
if (form.has("scope") && form.get("scope") !== SCOPE) {
return reply(res, 400, { error: "invalid_scope" });
}
const accessToken = randomBytes(32).toString("base64url");
tokens.set(accessToken, Date.now() + EXPIRES_IN * 1000);
reply(res, 200, { access_token: accessToken, token_type: "Bearer", expires_in: EXPIRES_IN, scope: SCOPE });
}).listen(8080);