# Amazon FWCIM Solver API

> Amazon metadata1 (FWCIM) generator API. Nullgate returns the metadata1 value for an Amazon sign-in form, and your HTTP client submits the form.

> FWCIM costs $0.50 per 1,000 generated `metadata1` values ([all prices](https://nullgate.club/en/prices)).

Amazon forms, such as the sign-in form, carry a hidden `metadata1` field. Nullgate calls this value FWCIM and bills it as `amazon.fwcim`.

1. Measure the page `timing` around your page request.
2. Call `session.page(url, html)`, then `page.fwcim(...)`.
3. Put `metadata1` into the form.
4. Call `wait()`, then submit the form at once with the result `headers`.

```python
import os
import time

import httpx

from nullgate import Nullgate

UA = (
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
    "(KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36"
)
url, email = os.environ["TARGET_URL"], os.environ["AMAZON_EMAIL"]
with Nullgate() as ng, httpx.Client(headers={"User-Agent": UA}) as http:
    start = time.time_ns() // 1_000_000
    response = http.get(url)
    end = time.time_ns() // 1_000_000
    performance_timing = {
        "navigationStart": start,
        "fetchStart": start,
        "responseEnd": end,
    }
    page = ng.session(user_agent=UA).page(url, response.text)
    fwcim = page.fwcim(
        form="#signin",
        timing=performance_timing,
        inputs={"ap_email": email},
        cookies=http.cookies,
    )
    form = {"ap_email": email, "metadata1": fwcim.metadata1}
    fwcim.wait()
    http.post(url, data=form, headers=fwcim.headers)
```

```typescript
import { readFile } from "node:fs/promises";
import { Nullgate } from "@nullgate/sdk";

// Save the observed HTML and browser performance.timing JSON before running.
const url = process.env.PAGE_URL ?? "https://www.amazon.com/ap/signin";
const html = await readFile("page.html", "utf8");
const timing: Record<string, number> = JSON.parse(
  await readFile("timing.json", "utf8"),
);
const userAgent =
  process.env.USER_AGENT ??
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36";
const page = new Nullgate().session({ userAgent }).page(url, html);
const fwcim = await page.fwcim({
  form: "#signIn",
  timing,
  inputs: { ap_email: process.env.EMAIL ?? "user@example.com" },
});
await fwcim.wait();
const form = new URLSearchParams({
  ap_email: process.env.EMAIL ?? "user@example.com",
});
form.set("metadata1", fwcim.metadata1);
// Send form through your existing client, with its existing target cookies.
```

## Arguments

| Argument  | Meaning                                                                                                                                                                                   |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `form`    | Optional CSS selector matching exactly one form. Without it, the built-in Amazon selectors must find exactly one form, for example `#signin` or `.fwcim-form` |
| `timing`  | When the page loaded, in Unix milliseconds, with the field names of the browser `performance.timing` object. `navigationStart` is required. No other nonzero value may be earlier than it |
| `inputs`  | The fields you filled, as `{id or name: value}`. Each field must be inside the form                                                                                                       |
| `cookies` | Optional. The cookies your client holds for the target. The SDK sends only `session-id`, `session-token` and `ubid-main` to Nullgate                                                      |
| `actions` | Optional observed interaction events |
| `submitted` | Defaults to `True` / `true`. Use false to collect before submission |
| `referrer` | Referring page URL. Defaults to `""` |
| `history_length` / `historyLength` | Optional positive browser history length. Otherwise the server starts at 1 and increments for a new document |

### Fields and passwords

`inputs` accepts raw non-password fields and `PreparedInput` summaries. Describe passwords with [`prepare_inputs()` / `prepareInputs()`](https://nullgate.club/en/akamai#sensor), never with a raw password.

### Field sizes

The server needs the size of every visible form field with an `id` or `name`: text, email, password, phone, date and number. It reads the size from:

- `style="width:…px;height:…px"`;
- the `width` and `height` attributes;
- the Amazon class `a-input-text`.

Otherwise, pass the measured size in list form: `inputs=[{"id": "captcha", "value": "", "geometry": {"width": 120, "height": 31}}]`. Hidden fields need no size.

### Omitted and empty lists

| You pass     | Effect                                                                                  |
| ------------ | --------------------------------------------------------------------------------------- |
| No `inputs`  | Keeps prior observations                                                                |
| `inputs=[]`  | Supplies no new field observations and clears current input goals, not existing field telemetry |
| No `actions` | The server can generate automatic actions                                               |
| `actions=[]` | Adds none and disables automatic actions for this call. Earlier events remain           |

### Document start

`started_at_ms` / `startedAtMs` in `session.page()` must equal `timing.navigationStart`. Without it, the SDK uses `timing.navigationStart` as the document start.

## Result

| Field        | Meaning                                                            |
| ------------ | ------------------------------------------------------------------ |
| `metadata1`  | The value for the form field `metadata1`                           |
| `headers`    | Headers to add to the form request                                 |
| `send_at`    | The earliest moment to submit the form. `wait()` sleeps until then |
| `request_id` | The identifier to quote to support                                 |

**Overload.** The API returns HTTP 503 `unavailable` with `Retry-After: 1`. You are not charged, and the session state does not change. The SDK does not retry this error.

## Common mistakes

| You see                         | Cause                                                         | Fix                                                                      |
| ------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `invalid_inputs`, password      | You passed a raw password | Use a prepared input summary |
| `invalid_inputs`, form selector | `form` matches no form or several forms                       | Use a selector that matches one form in the HTML you passed              |
| `invalid_inputs`, timing        | `timing` has no `navigationStart`, or a value earlier than it | Measure the times around your own page request |
| `invalid_request`, `Invalid field: inputs` | A visible form field has no known size, or `checksum`, `text` or `geometry` does not fit the field | Pass `geometry` for that field |

## ACIC challenges

ACIC is a separate Amazon challenge: a proof of work (PoW), an AWS WAF image puzzle, or both. Each generated PoW or WAF round costs one `amazon.acic` operation. See the [ACIC guide](https://nullgate.club/en/amazon-acic) and the [HTTP reference](https://nullgate.club/en/http#amazon-acic).
