Minimal HTTP client
A small Node.js (ESM) helper to replay cookbook recipes. It accepts Bearer or a session cookie (see Authentication).
- Node.js
- curl
- GraphQL
// ubloClient.mjs
const ENDPOINT =
process.env.UBLO_GRAPHQL_URL ?? 'https://example.ublo.immo/api/graphql';
/**
* @param {string} query
* @param {Record<string, unknown>} [variables]
* @param {{ token?: string, cookieJar?: string }} [auth]
*/
export async function ublo(query, variables, auth = {}) {
const token = auth.token ?? process.env.UBLO_API_TOKEN;
const cookieJar = auth.cookieJar ?? process.env.UBLO_COOKIE;
if (!token && !cookieJar) {
throw new Error('Provide UBLO_API_TOKEN (Bearer) or UBLO_COOKIE (session)');
}
const headers = {
'Content-Type': 'application/json',
Accept: 'application/json',
};
if (token) headers.Authorization = `Bearer ${token}`;
if (cookieJar) headers.Cookie = cookieJar;
const res = await fetch(ENDPOINT, {
method: 'POST',
headers,
body: JSON.stringify({ query, variables }),
});
const json = await res.json();
// GraphQL may return HTTP 200 + errors[]
if (json.errors?.length) {
const detail = JSON.stringify(json.errors, null, 2);
throw new Error(`GraphQL errors:\n${detail}`);
}
return json.data;
}
Usage (Bearer via env):
import { ublo } from './ubloClient.mjs';
const data = await ublo(`
query GetCompany {
company { id name }
}
`);
Usage (session cookie):
const data = await ublo(
`query GetCompany { company { id name } }`,
undefined,
{ cookieJar: process.env.UBLO_COOKIE }, // e.g. "UBLO_TOKEN_AUTHENTICATION=…"
);
- Bearer
- Cookie session
export UBLO_GRAPHQL_URL='https://example.ublo.immo/api/graphql'
export UBLO_API_TOKEN='eyJ…'
curl -sS -X POST "$UBLO_GRAPHQL_URL" \
-H "Authorization: Bearer $UBLO_API_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"query":"query { company { id name } }"}' | jq .
export UBLO_GRAPHQL_URL='https://example.ublo.immo/api/graphql'
# cookies.txt produced by: curl … -c cookies.txt … (login mutation)
curl -sS -X POST "$UBLO_GRAPHQL_URL" \
-H 'Content-Type: application/json' \
-b cookies.txt \
-d '{"query":"query { company { id name } }"}' | jq .
query GetCompany {
company {
id
name
}
}
Auth variants in this cookbook
Every curl tab offers Bearer and Cookie session (groupId="auth"). The Node helper reads UBLO_API_TOKEN or UBLO_COOKIE.
Integration checklist
| Point | Why |
|---|---|
Single endpoint POST /api/graphql | No public business REST for integrations |
Read errors[] even on HTTP 200 | Standard Ublo GraphQL pattern |
| Request only needed fields | Perf + more stable contracts |
Store externalId / customReference | Reconciliation with your system |
Do not use /search | Internal route — unsupported for integrations |
See also official best practices.