# PingOne Protect API

> Generate PingOne Protect data using the site's SDK script and your own HTTP transport.

> Protect costs $0.50 per 1,000 successful results. Prepare is free. [All prices](https://nullgate.club/en/prices).

To receive `data` through one HTTP call, use [`POST /solve` with `type: "pingone"`](https://nullgate.club/en/solver). The sections below explain token handling, configuration and signed inputs in the SDK.

## Advanced: SDK flow

In this flow, you fetch the page and its actual PingOne SDK script, send the token request through your client, and submit the result yourself.

1. Fetch the target page and its PingOne SDK script with your target client. Use the same user agent and session as your target flow.
2. Create a browser session and page. Pass the script source and a `send` callback to `protect`.
3. The SDK calls free `/pingone/prepare` and passes its token GET request to `send`. Send the request using your target transport and return the response. Keep cookies and proxy settings in that transport.
4. The SDK calls `/pingone/protect` and returns encoded `data`. Include it in the site's normal request as required by that site.

Use the actual script from the target site, not an example script. The SDK accepts a supplied client token instead of `send` when you already have one. The SDK retains continuation state and handles gzip and one recovery when retained script state is missing. Keep passing the script source to the SDK.

### Python

```python
# page is ng.session(user_agent=ua).page(url, html).
# send(request) uses your target client and returns TargetResponse.
result = page.protect(script=script_source, send=send)
data = result.data
```

The async SDK uses `await page.protect(...)`. See the complete [Python example](https://github.com/nullgate-club/nullgate-sdk-py/blob/main/examples/pingone.py) for the callback and page and script fetches.

### TypeScript

```typescript
// page is ng.session({ userAgent }).page(url, html).
// send is a TargetFetch backed by your target client.
const result = await page.protect({ script: scriptSource, send });
const data = result.data;
```

See the [TypeScript example](https://github.com/nullgate-club/nullgate-sdk-ts/blob/main/examples/pingone.ts) for the callback. Native `fetch` has no cookie jar. Use a cookie-aware transport when the target requires one.

### Go

```go
// session is client.PingOne.Session(visit), and page belongs to visit.
result, err := session.Protect(ctx, page, pingone.Options{
    Script: scriptSource,
    Send: target.Do,
})
if err != nil { return err }
data := result.Data
```

See the [Go example](https://github.com/nullgate-club/nullgate-sdk-go/blob/main/examples/pingone/main.go). Use the same target client and cookie jar for the page, script, and token request.

## Identity and signed inputs

The generated device identity is stable for the same profile UUID, Nullgate API key, and site origin. Changing any of them, including rotating the API key, changes the generated identity. Keep the same profile and key when continuity matters.

You may supply a device attributes JWT as `jwt_device_attributes`, `jwtDeviceAttributes`, or `JWTDeviceAttributes`. The service passes the supplied JWT unchanged. If the site's SDK configuration enables the agent flag, provide the agent JWT as `jwt_agent_payload`, `jwtAgentPayload`, or `JWTAgentPayload`. The service does not create that JWT. Supply other SDK configuration and behavioral data only when available from your flow.

## HTTP API and errors

[HTTP reference](https://nullgate.club/en/http#pingone-protect) · [OpenAPI schema](https://nullgate.club/openapi/pingone.json)

`POST /pingone/prepare` is authenticated and free. `POST /pingone/protect` charges for each successful result, even if the target later rejects it. Invalid requests return HTTP 400. Insufficient balance returns HTTP 402. Missing retained script returns HTTP 428 `script_required`: retry with the full script. See [Errors](https://nullgate.club/en/errors).
