API Integration

A JSON Response Is Not Yet a Product Record

A successful HTTP request and valid JSON are only the start of a reliable data workflow. Before an agent compares products or recommends an action, its client must prove that the response has the expected shape, that each row is usable, and that missing values remain missing—not silently converted into certainty.

5 min read Pangol Info Team
A response passes through envelope checks, field validation, and normalization before reaching a decision.
Illustration: validate the envelope and record fields before normalizing data for a decision.

A successful HTTP request and valid JSON are only the start of a reliable data workflow. Before an agent compares products or recommends an action, its client must prove that the response has the expected shape, that each row is usable, and that missing values remain missing—not silently converted into certainty.

The distinction matters because applications often turn a nested response into a business decision in one line: results[0].price. If the wrapper, parser, or individual record differs from what the code expects, that shortcut can fail loudly—or worse, produce a plausible but wrong answer.

The current Pangolinfo Amazon Scraper API example shows structured output nested under data.json[0].data.results. That is a useful contract to adapt to, not a reason to assume every parser, format, or future response has the same shape.

Put a boundary between JSON and your application

Treat the response body as unknown until it crosses a small adapter. Keep three questions separate:

  1. Did the request reach the API and return an HTTP response?
  2. Did the API report a successful operation, with the expected response envelope?
  3. Does each returned row satisfy the fields this particular application needs?

These are different outcomes. An HTTP error is not an empty search. An API-level error is not a successful response with zero results. A valid envelope containing an empty results array is not a malformed response. Give each state its own outcome so downstream code can respond accurately.

Here is a deliberately narrow TypeScript sketch for the documented nested example. It demonstrates the boundary; it is not a generated SDK or a universal decoder for every parser and output format.

type JsonObject = Record<string, unknown>;

type DecodeResult =
  | { kind: "ok"; rows: unknown[] }
  | { kind: "empty" }
  | { kind: "api_error"; code: unknown; message?: string }
  | { kind: "invalid_shape"; at: string };

function object(value: unknown): JsonObject | undefined {
  return value !== null && typeof value === "object" && !Array.isArray(value)
    ? value as JsonObject
    : undefined;
}

function decodeDocumentedEnvelope(payload: unknown): DecodeResult {
  const root = object(payload);
  if (!root) return { kind: "invalid_shape", at: "root" };

  if (typeof root.code !== "number") {
    return { kind: "invalid_shape", at: "code" };
  }
  if (root.code !== 0) {
    return {
      kind: "api_error",
      code: root.code,
      message: typeof root.message === "string" ? root.message : undefined,
    };
  }

  const data = object(root.data);
  const pages = data?.json;
  if (!Array.isArray(pages) || pages.length === 0) {
    return { kind: "invalid_shape", at: "data.json" };
  }

  const first = object(pages[0]);
  const inner = object(first?.data);
  const rows = inner?.results;
  if (!Array.isArray(rows)) {
    return { kind: "invalid_shape", at: "data.json[0].data.results" };
  }

  return rows.length === 0 ? { kind: "empty" } : { kind: "ok", rows };
}

An adapter like this makes the point of failure explicit. In production, derive the decoder from the exact operation and format you call, and represent transport errors separately from decoded API results.

Validate the fields the decision actually uses

A result row may be an object without containing every field your application wants. Validate the minimum contract for the task, not an imagined universal product schema.

For a keyword-search workflow, that might mean requiring a usable product identifier before deduplication, while treating title, price, rank, or image as optional if the next step can work without them. For a price comparison, a price string may be necessary—but the application should still preserve its original text and avoid interpreting an absent value as zero.

type ProductRow = {
  asin: string;
  title?: string;
  price?: string;
};

type RowCheck =
  | { kind: "usable"; product: ProductRow }
  | { kind: "rejected"; reason: string };

function validateProductRow(value: unknown): RowCheck {
  const row = object(value);
  if (!row) return { kind: "rejected", reason: "row_not_object" };
  if (typeof row.asin !== "string" || row.asin.trim() === "") {
    return { kind: "rejected", reason: "missing_asin" };
  }

  return {
    kind: "usable",
    product: {
      asin: row.asin,
      ...(typeof row.title === "string" ? { title: row.title } : {}),
      ...(typeof row.price === "string" ? { price: row.price } : {}),
    },
  };
}

This is intentionally conservative. It does not parse prices into numbers, claim a shipping total, or invent a missing title. A separate, tested domain layer can normalize a price when the business task has defined currency, locale, and offer semantics.

Keep good rows when one row is bad

One malformed record need not erase the rest of a useful result. Validate rows independently, keep usable rows, and count or log rejected rows with reasons. That lets the caller choose an appropriate response: continue with a smaller set, retry a particular request if warranted, or ask for human review when too little evidence remains.

Do not silently drop the entire error context. A useful internal result can carry both usableProducts and rejectedRows, plus the request context that produced them. The user-facing answer should then be based only on the usable evidence, with a caveat when the rejected portion could change the conclusion.

Keep request context beside the records

A product row without its request context can be hard to interpret later. Store the inputs that define what was asked for—such as parser, marketplace, content or target identifier, output format, and any delivery-location context—alongside the ingestion record. Do not put credentials in logs.

Record your own received_at timestamp as the time your system received the response. Do not relabel it as the time the source page was observed unless the API explicitly supplies that source timestamp. This distinction is especially useful when debugging a monitor or explaining why two runs differ.

Test the boundary with fixtures

A small fixture set catches more brittle clients than a happy-path test alone. Build tests for:

  • the documented successful envelope with one valid row;
  • a non-success API code;
  • a valid envelope with an empty result array;
  • a missing or wrongly typed results field;
  • a row without the identifier your workflow requires;
  • a valid row with optional fields missing.

For each fixture, assert the outcome category and the downstream behavior—not just that JSON.parse did not throw. A schema change should become a visible adapter failure, not a product recommendation built from a default value.

Make uncertainty a first-class result

The goal is not to reject every partial response. It is to make the limits legible. A client can return usable records and still say that a requested field is absent; it can report an empty result without implying the product does not exist; it can stop a price comparison when the required price is unavailable.

That small boundary between transport JSON and application data is where an API integration earns trust. Check the selected operation’s response contract in the Amazon Scraper API reference, validate only what your decision needs, and let the application’s uncertainty survive all the way to the answer.

Amazon Scraping API & Data Quality · Supporting guides

Explore this topic cluster

Start with the pillar, then follow a practical path through setup, extraction quality, and response validation.

Explore the API contract

Check the operation-specific response shape before wiring API data into a product decision.

Amazon Scraper API reference