> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apostra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reading what is waiting on your seller account

> How a seller account reads everything waiting on someone, and how it resolves a failed GAM order, with get_status and save_work_item.

Pending operations is the queue your Storefront keeps of everything that is waiting on someone: buys waiting for your
approval, creatives waiting for your review, buys that failed to reach a source, work a source needs from you, and
failed GAM orders the platform could not remove. The Pending operations page in the web app and in chat shows it. A
seller account can read the same queue with `get_status`, and can read and resolve the failed GAM orders in it with the
same tools an agent uses for any other work item.

## Read the queue

Call `get_status` with `include: ["pendingOperations"]`. Only a seller account takes it. A buyer, organization or
developer account that sends it is refused with `VALIDATION_ERROR` on the field `include`.

```json theme={null}
{ "include": ["pendingOperations"] }
```

The answer is the usual status plus a `pendingOperations` object. A group appears only when something is in it, so an
empty object means nothing is waiting on anyone. `null` means the read failed: `pendingOperationsDiagnostic` says so,
and the rest of the status is still returned. When the call does not ask for it, the key is absent and the status is
exactly what it was before.

| Group | What is waiting |
| - | - |
| `approvals` | Media buys, and changes to live buys, waiting for your approval. |
| `creativeReviews` | Creatives waiting for your review. |
| `failedForwards` | Approved buys that never reached a source, grouped by error code, each with the action that fits its recovery class. |
| `awaitingSource` | Buys a source accepted asynchronously and is still moderating. |
| `updatesAwaitingSource` | Changes to live buys a source accepted and has not applied yet. |
| `creativesAwaitingSource` | Approved creatives a source has not accepted yet. |
| `manualSourceWork` | Booking, creative sync and final-report work a source needs a person to do, grouped by buyer, buy and source. |
| `sourceDegradations` | Source problems you own. Problems Apostra or a vendor owns never appear. |
| `gamCleanups` | Failed GAM orders you have not resolved. |

Each group carries `count`, and each item says who it is waiting on and since when. `manualSourceWork` is the one group
that pages. It returns up to 200 items; `count` and `mediaBuyCount` cover the whole backlog, and `nextOffset` is where the
next page starts. Send `manualWorkTake` (1 to 200) and `manualWorkSkip` with `include: ["pendingOperations"]` to read it
a page at a time. Sending either without the include is refused.

The answer is the same one the Pending operations page reads. It is not a copy, so the two cannot disagree.

## Read a failed GAM order

When a booking fails after the platform created an order in your GAM, the platform tries to clear the order. When it
cannot, the order waits on you. It is a work item of the kind `gam_cleanup`.

```json theme={null}
{ "kind": "work_item", "filter": { "workItemKind": "gam_cleanup" } }
```

Call `search` with that to list them, or `get` with `kind: "work_item"`, `workItemKind: "gam_cleanup"` and the item's
`id` to read one. A cleanup is `pending` until you resolve it, and a resolved cleanup leaves the list, so `pending` is
the only status you can filter for. A read of one that is resolved, or that the platform archived, answers `NOT_FOUND`.

| Field | Meaning |
| - | - |
| `id` | The cleanup's operation id. Pass it to `save_work_item`. |
| `gamCleanup.orderId` | The GAM order. You repeat it when you resolve the cleanup, as your confirmation. |
| `gamCleanup.sourceId`, `gamCleanup.sourceName` | The source whose booking failed. |
| `gamCleanup.outcome` | `failed` or `refused`: how the platform's last attempt to clear the order ended. |
| `gamCleanup.safeToCleanup` | Whether the platform verified the order is an unbooked draft with no spend. |
| `gamCleanup.requiredPermission` | The GAM permission archiving needs, when that is what is missing. |
| `gamCleanup.safeNextAction` | `retry_cleanup`, `grant_archive_orders_and_recheck`, `reauthenticate_and_recheck`, `clean_up_manually_in_gam`, `review_order_in_gam` or `none`. The text of the answer says what to do for each. |

## Resolve a failed GAM order

Call `save_work_item` with `kind: "gam_cleanup"`, `status: "completed"` and a `gamCleanup` object. There are two ways
to resolve a cleanup.

Ask the platform to archive the order. It checks again that the order is safe to archive, then archives it in your GAM:

```json theme={null}
{
  "kind": "gam_cleanup",
  "id": "OPERATION_ID",
  "status": "completed",
  "gamCleanup": { "mode": "archive", "orderId": "GAM_ORDER_ID" }
}
```

Or record that you cleaned the order up in GAM yourself. A `note` of up to 500 characters, saying what you did, is
required for `manual` and is not allowed for `archive`:

```json theme={null}
{
  "kind": "gam_cleanup",
  "id": "OPERATION_ID",
  "status": "completed",
  "gamCleanup": { "mode": "manual", "orderId": "GAM_ORDER_ID", "note": "Archived the order in GAM" }
}
```

The rules:

* Only an administrator of the Storefront account can resolve a cleanup. Anyone else is refused with `ACCESS_DENIED`.
* `orderId` must match the order of that cleanup, or the call is refused with `VALIDATION_ERROR` and nothing changes.
* A resolution needs no approval on our site. The order is yours, you have already read it, and the platform archives
  only an order it verified is an unbooked draft. This is not a billing or access change.
* An archive the platform could not complete does not resolve the cleanup. The answer is an error with the code
  `GAM_CLEANUP_NOT_RESOLVED` and an `attempt` object (`outcome`, `retryDisposition`, `safeNextAction` and
  `requiredPermission`) that says what to do next. The cleanup stays pending.
* Repeating the same resolution succeeds again and does nothing a second time. Resolving an order a second time by the
  other method is refused with `CONFLICT`.
* A successful answer has `action: "created"` and an `object` with `status: "completed"`, and the cleanup no longer
  appears in the queue.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.