Skip to main content

Minimal HTTP client

Reconstructed

A small Node.js (ESM) helper to replay cookbook recipes. It accepts Bearer or a session cookie (see Authentication).

// 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=…"
);
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

PointWhy
Single endpoint POST /api/graphqlNo public business REST for integrations
Read errors[] even on HTTP 200Standard Ublo GraphQL pattern
Request only needed fieldsPerf + more stable contracts
Store externalId / customReferenceReconciliation with your system
Do not use /searchInternal route — unsupported for integrations

See also official best practices.