Skip to main content
TagManifest /Docs Dashboard

Node.js

Node.js client options for the TagManifest API. Manual fetch wrapper and generated client via openapi-generator-cli.

On this page 5

There is no officially published npm package for TagManifest today. This page documents two approaches that work against the live API: a minimal manual fetch wrapper suitable for most use cases, and a generated TypeScript client from the OpenAPI spec for teams that want full type coverage.

Beta — generated client not officially published yet. The OpenAPI spec at /openapi.json is stable, but the generated npm package is not in the registry. Use the manual wrapper for production, or generate a local client from the spec.

Status

The TagManifest REST API is stable and versioned at the path level. All six endpoints work with any HTTP client. An officially maintained npm package is planned; until then, the approaches below cover the full API surface.

Manual fetch wrapper

The wrapper below covers POST /scan-url, POST /scan, POST /evaluate-rule, GET /rules and GET /rules-detail?rule_id=, with error normalization and the TM_API_KEY environment variable convention. Paths are written without a trailing slash, as on the endpoint pages.

The API refuses unknown fields and query parameters with a 400, so pass only the fields each endpoint page lists.

const BASE = "https://developer.tagmanifest.com/v1";

async function call(path, method, payload, apiKey) {
  const opts = {
    method,
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
  };
  if (payload) opts.body = JSON.stringify(payload);
  const res = await fetch(`${BASE}${path}`, opts);
  if (!res.ok) {
    const body = await res.json().catch(() => ({}));
    const err = new Error(body.error || res.statusText);
    err.status = res.status;
    err.body = body;
    throw err;
  }
  return res.json();
}

export const tagmanifest = {
  scanUrl: (params) => call("/scan-url", "POST", params, process.env.TM_API_KEY),
  scanContainer: (params) => call("/scan", "POST", params, process.env.TM_API_KEY),
  evaluateRule: (params) => call("/evaluate-rule", "POST", params, process.env.TM_API_KEY),
  // query may hold category, tier, status and limit. Any other key is refused with 400.
  listRules: (query = {}) => {
    const qs = new URLSearchParams(query).toString();
    return call(`/rules${qs ? "?" + qs : ""}`, "GET", null, process.env.TM_API_KEY);
  },
  getRule: (ruleId) =>
    call(`/rules-detail?rule_id=${encodeURIComponent(ruleId)}`, "GET", null, process.env.TM_API_KEY),
};

Node.js 18+ includes the global fetch implementation used above. For older Node versions, substitute node-fetch or undici.

Generated client

The OpenAPI spec is available at https://developer.tagmanifest.com/openapi.json. Use openapi-generator-cli to produce a typed TypeScript client:

npx @openapitools/openapi-generator-cli generate \
  -i https://developer.tagmanifest.com/openapi.json \
  -g typescript-fetch \
  -o ./tagmanifest-client \
  --additional-properties=supportsES6=true,npmName=tagmanifest-client

The typescript-fetch generator produces a client that works in Node.js and browser environments. After generation:

cd tagmanifest-client
npm install
npm run build

Then import and configure:

import { Configuration, DefaultApi } from "./tagmanifest-client";

const config = new Configuration({
  basePath: "https://developer.tagmanifest.com/v1",
  accessToken: process.env.TM_API_KEY,
});

const api = new DefaultApi(config);
const result = await api.scanUrl({
  scanUrlRequest: { url: "https://example.com", topN: 25 },
});
console.log(result.healthScore?.score);

Method names come from the operationId values in the spec: scanUrl, scanContainer, evaluateRule, listRules, getRule. The exact class, method and parameter names depend on the generator version. Check the README the generator writes into the output folder.

Regenerate the client whenever you pull a new version of the spec. The spec is hand-authored from the live function source and updated when endpoints change.

Error handling

All non-2xx responses return a JSON body with an error string. The manual wrapper above normalizes these into JavaScript Error objects with a status property. In the generated client, the generator wraps non-2xx responses in a ResponseError with the raw response attached.

The errors you are most likely to encounter:

StatusCause
400Missing, malformed or unknown request field — check parameter names and types. A misspelt field is refused, not ignored.
401Invalid or missing API key — check TM_API_KEY.
429Daily rate limit exceeded — read reset_at from the body and back off.
502The target URL or GTM CDN was unreachable — retry with backoff.

See Errors for the full list.

Rate-limit headers

Responses to requests that were counted include X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. That covers 200 responses, the 429, and errors such as 400, 404 and 502. The headers are absent on 401, 403, 405 and 503 responses, so check that they exist before reading them:

const res = await fetch(`${BASE}/scan-url`, { /* … */ });
const remainingHeader = res.headers.get("X-RateLimit-Remaining");
const resetAt = res.headers.get("X-RateLimit-Reset");

if (remainingHeader !== null && parseInt(remainingHeader, 10) < 5) {
  console.warn(`Approaching scan_url limit. Resets at ${resetAt}`);
}

When the limit is reached, wait until the reset time. There are no paid plans and no way to raise a limit. See Rate limits for daily caps by tool.

Examples

Manual wrapper — scan URL
const BASE = "https://developer.tagmanifest.com/v1";

async function scanUrl(params, apiKey) {
  const res = await fetch(`${BASE}/scan-url`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(params),
  });
  if (!res.ok) {
    const err = await res.json().catch(() => ({}));
    throw Object.assign(
      new Error(err.error || res.statusText),
      { status: res.status }
    );
  }
  return res.json();
}

// Usage
const result = await scanUrl(
  { url: "https://example.com", top_n: 25 },
  process.env.TM_API_KEY
);
console.log(result.health_score.score);
Generated client install
npx @openapitools/openapi-generator-cli generate \
  -i https://developer.tagmanifest.com/openapi.json \
  -g typescript-fetch \
  -o ./tagmanifest-client \
  --additional-properties=supportsES6=true,npmName=tagmanifest-client

cd tagmanifest-client && npm install && npm run build