> ## 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.

# Upload a wholesale pricing feed or a buyer account feed as a Library document

> Save a wholesale pricing feed or a buyer account mapping feed as a Library document, preview it with get, and commit it with save_material. A pricing feed replaces live prices, so an administrator approves it on our site.

A wholesale pricing feed gives a source the prices and availability your ad server cannot expose. A
buyer account feed maps each buyer account to the account it uses in your ad server. Both are Library
documents, saved, previewed and committed the way a rate card or an avails sheet is. The Inventory Feed
Page and the Buyer Account Mapping import use the same checks and the same services, so what the page
shows and what an agent reads are the same.

| Feed | `metadata.documentType` | Preview include | Commit |
| - | - | - | - |
| Wholesale pricing feed | `wholesale_pricing_feed` | `wholesale_pricing_preview` | `save_material` with `commitPreview` records a request. An administrator approves it on our site and the prices change then. |
| Buyer account feed | `seller_account_feed` | `seller_account_feed_preview` | `save_material` with `commitPreview` commits on the call, for an administrator. |

## Get the pricing template

Read the source with the `feedTemplate` include:

```json theme={null}
{
  "kind": "inventory_source",
  "id": "SOURCE_ID",
  "include": ["feedTemplate"]
}
```

The answer has a `feedTemplate` with the file name, the `columns`, `rowCount` and `csvText`: one row for
each ad-server selector the source products use, with everything Apostra already knows filled in. You
add the CPM percentiles, the monthly impressions and the window. A very large template stops at a whole
row after 200,000 characters and says `truncated: true`. A source that cannot carry wholesale pricing
leaves the include out and says why under `unavailableIncludes`.

## Save the pricing feed

Save the completed CSV as a Material. Name the source it prices in `metadata.inventorySourceId`, the
source `id` from `search`:

```json theme={null}
{
  "clientRequestId": "pricing-2027-01",
  "source": { "kind": "inline", "name": "pricing-2027-01.csv", "content": "ad_server_selector,..." },
  "metadata": {
    "documentType": "wholesale_pricing_feed",
    "inventorySourceId": "SOURCE_ID"
  }
}
```

The source must be a modular source or a managed ad-server source of your account. The feed can also be
an uploaded CSV or XLSX file. Saving changes no price.

## Preview it

```json theme={null}
{
  "kind": "material",
  "id": "MATERIAL_ID",
  "include": ["wholesale_pricing_preview"]
}
```

`included.wholesalePricingPreview` holds:

| Field | Meaning |
| - | - |
| `accepted`, `acceptedTotal` | Up to 100 accepted rows (selector, type, country, currency, floor and percentile CPMs, monthly impressions, window), and the full count. Selectors are your own text and arrive fenced as data. |
| `rejected`, `rejectedTotal`, `warnings` | Up to 100 rows each, with the row number, the column, a code and a message. |
| `currency`, `effectiveFrom`, `effectiveTo` | The one currency of the feed and its window. A row priced outside the storefront currency is rejected. |
| `selectorMatch` | Whether the selectors match the source products, with the count and the first unmatched selectors. `available: false` means the source has not synced products yet. |
| `live` | What the commit replaces: the newest completed import and how many price rows are live now. |
| `previewToken` | Signed, and bound to this revision, its bytes and the live feed. It is `null` while any row is rejected, because a feed commits only when none is. |

## Commit it: an administrator approves

Committing replaces every price the source has, and buyers see the new prices at once. So the commit does
not change anything. It checks the token and records a request:

```json theme={null}
{
  "materialId": "MATERIAL_ID",
  "commitPreview": { "sourceRevision": 1, "previewToken": "TOKEN" }
}
```

The answer is `approval_required`, with a link to the approval page and an `idempotencyKey`:

```json theme={null}
{
  "action": "approval_required",
  "message": "Approval needed for inventory_feed.wholesale_pricing_commit. ...",
  "approval": { "kind": "inventory_feed.wholesale_pricing_commit", "state": "pending", "url": "https://..." },
  "idempotencyKey": "inventory_feed.wholesale_pricing_commit:..."
}
```

Show the link to an administrator of the account. They see what will be replaced and how many rows are live
now, and approve or reject on our site, signed in as themselves. Nothing changes before that. Repeat the
same `save_material` call to read the outcome: it returns the same request while it waits, and the commit
result once it has run. If the feed is already the live one, the answer is
`wholesale_pricing_already_live` and nothing is recorded. See
[Web approvals](https://docs.apostra.com/v2/concepts/web-approvals.md) for how an approval works.

The approval commits exactly the feed you previewed. When the administrator approves, it runs again against
what is true now, and it refuses, and changes nothing, with a named reason when:

| Reason | What changed |
| - | - |
| `material_changed` | The document has a newer revision, or its bytes or its source changed. |
| `feed_changed` | The rows no longer parse to the rows that were approved, for example because the storefront currency changed. |
| `feed_rejected` | A row is rejected now. |
| `feed_not_found` | The document or the source is gone. |
| `live_prices_changed` | The live prices are not the ones the feed was previewed against, because another feed landed first. Preview again and ask again. |
| `approver_access_revoked` | The approver no longer has access to the account. |

A busy source, or a lost connection, leaves the approval running and it is tried again. It never reports
success for a commit that did not happen.

## The buyer account feed

A buyer account feed is the `source_account_bindings.csv` that maps buyers to accounts in bulk, the same
file the [Buyer Account Mapping Page](https://docs.apostra.com/v3/seller-buyer-account-mapping-page.md) imports. Save it as a Material with
`documentType: "seller_account_feed"`. `metadata.feedMode` is `snapshot` (the default) or `delta`. A snapshot
lists every binding of the sources it names, and a row left out archives only a binding this feed created.
A delta changes only the rows it lists and must follow the feed latest committed revision.

The file is a CSV with one row for each binding. An account that maps buyers by their complete account key
uses `schema_version` 2 and these columns:

```text theme={null}
schema_version,operation,operator_domain,operator_unit_id,brand_domain,brand_id,brand_countries,currency,timezone,sandbox,inventory_source_key,binding_mode,source_external_account_id
```

An account that still maps by operator and brand uses `schema_version` 1 and the columns
`schema_version,operation,operator_domain,brand_domain,inventory_source_key,source_external_account_id`. A
file in the other version is refused, never converted.

* `operation` is `upsert` or `archive`. An `upsert` row needs `source_external_account_id`, the account id
  the ad server lists for the buyer.
* `operator_domain` is a registrable domain. `brand_domain` may be a subdomain but not a `www.` host.
* `binding_mode` is `dedicated` or `shared_default`. A feed never turns one into the other for the same
  account.
* `brand_countries` is empty or a sorted JSON array of ISO country codes.
* `inventory_source_key` is the `sourceId` of a source of your account that carries a native account.

The feed creates no buyer, no relationship and no ad-server account. A row that names something your
account does not have is quarantined, and the preview says why.

```json theme={null}
{ "kind": "material", "id": "MATERIAL_ID", "include": ["seller_account_feed_preview"] }
```

`included.sellerAccountFeedPreview` holds the `state` (`preview_ready` or `validation_failed`), the `impact`
counts (create, update, archive, unchanged, quarantine, duplicate), up to 200 `diagnostics`, and a
`previewToken` that is `null` until the feed can commit. A snapshot with any quarantined row cannot commit.
Correct the file and save it again as a new revision.

Commit it with `save_material` and `commitPreview`. This feed changes neither a price nor who may buy: it
only maps an existing buyer relationship to an account the source already lists. So it commits on the call,
for an administrator, and the answer says how many bindings were created, updated and archived. Repeating the
same call answers `idempotentReplay: true`. A revision that is already committed cannot be previewed again:
save the file as a new revision to change the mappings. A commit also refuses, and writes no binding, when the
document has a newer revision than the one you previewed: preview the current revision and commit that.

## What the pages do

The Inventory Feed Page commits a pricing feed the same way: it records the request and shows the approval
link, and nothing is committed until an administrator approves. Its download of the template and its preview
read the same functions as the calls above.


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