# WA Agency Amazon Spend - Orders, Categories, UNSPSC (`j0401/wa-amazon-spend`) Actor

Washington agencies' Amazon Business purchases (944k line items, FY18-26): which agency bought what, from whom, for how much, under which UNSPSC commodity code. Filter by agency, product category, brand, UNSPSC, date, amount; aggregate spend by agency/category/brand.

- **URL**: https://apify.com/j0401/wa-amazon-spend.md
- **Developed by:** [Wenhao Yang](https://apify.com/j0401) (community)
- **Categories:**
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 wa agency amazon spend records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## WA Agency Amazon Spend (`wa-amazon-spend`)

Pull **Washington state agencies' Amazon Business purchases** - **944,699 line items / $81M** across 9 fiscal years (FY18-FY26), from the state's free public open data.

This is the **long tail of government procurement**: every individual order an agency places through Amazon - the laptop, the LEGO set, the lab beaker, the printer toner - that nobody else tracks. It is the counterpart to [WA Master Contracts](https://apify.com/J0401/wa-master-contracts): master contracts show the big negotiated vendors; this shows the day-to-day retail spend underneath.

Built for **AI agents, developers, and market-intelligence / audit users** who want to know *what WA agencies are actually buying*, from whom, at what price, under which **UNSPSC** commodity code.

### What this data is

Each record is one **line item** - an agency's purchase of one product:

| Field | Meaning |
|---|---|
| `agencyName` | The buying agency (e.g. `SOCIAL AND HEALTH SERVICES DEPT`) |
| `orderDate` / `paymentDate` | Order / payment date |
| `productCategory` / `productTitle` | Amazon's category + the product's full title |
| `brand` / `manufacturer` / `sellerName` | Who makes / sells it |
| `unspsc` | 8-digit UNSPSC commodity code (FY19+; FY18 predates the column) |
| `quantity` / `itemSubtotal` / `shippingHandling` / `tax` / `netTotal` | What it cost |
| `fiscalYear` | Which FY dataset it came from |

> **UNSPSC is the unique angle.** Master contracts and agency contracts carry no product codes - Amazon spend does. So you can query "what agencies bought under commodity class 44 (office equipment)" directly.

### Typical questions it answers

- **What is an agency buying from Amazon?** `agencyName=NATURAL RESOURCES` -> every line item.
- **Who spends the most?** Aggregate by `agency` -> total spend + order count.
- **What categories dominate?** Aggregate by `productCategory` -> the tail of office/safety/IT spend.
- **Surge / anomaly monitoring** - which agency's Amazon spend spiked this quarter? Aggregate by agency + `dateFrom`, compare against last quarter. **Audit signals.**
- **Specific products / vendors** - `keywords=["LEGO"]`, `brand=HP`, or an 8-digit `unspsc=60141100`.
- **Big-ticket orders** - `minNetTotal=1000` for orders over $1k.

### Aggregate mode (server-side)

Turn on **`aggregate`** and it rolls up spend **on the source** - which means it works over the **whole 944k-row corpus instantly**, no matter how broad your filters:

| Output field | Meaning |
|---|---|
| `key` | The agency / product category / brand / fiscal year |
| `totalNet` | Total net spend for that group |
| `orders` | Number of line items |

Group by `agency` (who spends most), `productCategory` (what dominates), `brand`, or `fiscalYear`.

### Inputs (all optional)

| Input | What it does |
|---|---|
| `keywords` | Match any keyword against product title / brand / seller |
| `agencyName` | Substring match on the buying agency |
| `productCategory` | Substring match on Amazon's category |
| `brand` | Substring match on brand |
| `unspsc` | 8-digit UNSPSC code - accept 1/2/4/6/8 digits (exact at 8). FY18 auto-skipped |
| `dateFrom` / `dateTo` | Order date range (YYYY-MM-DD) |
| `minNetTotal` | Only orders at or above a dollar amount |
| `fiscalYear` | Restrict to one FY dataset (FY18-FY26), or all |
| `aggregate` + `groupBy` | Roll up by `agency` / `productCategory` / `brand` / `fiscalYear` -> totalNet + orders |
| `maxResults` | Cap the number of records (default 200) |

### Low cost, server-side

**From $0.001 per record** - with a per-run charge cap so even a full-corpus aggregate can't surprise-bill.

This is **nine fiscal years of Washington agencies' Amazon purchases** - the state publishes each FY as a *separate* dataset, and the schemas **drift across years**: FY18 has no commodity-code column at all, and the same column that is numeric in FY19 is *text* in FY22. We merge all nine onto one query surface that knows each year's shape, so a filter over the whole 2018-2026 span works even where a naive query would hit a type mismatch. Filters, counts and roll-ups are pushed down to the source (`$where` / `$group`) - the ~944k-row / ~440MB corpus is never bulk-downloaded; an unfiltered run returns the most recent line items as a live monitoring feed.

### Data source & freshness

- **Source**: [data.wa.gov - State Agency Amazon Spend](https://data.wa.gov/) (Socrata SODA API, free public, no login) - 9 fiscal-year datasets.
- **Update cadence**: near-daily as orders are reported - the freshest state spend data on WA open data.
- **Coverage**: agency purchases through Amazon Business only. FY18 has no UNSPSC column (schema predates it).

# Actor input Schema

## `keywords` (type: `array`):

Only return line items whose product title, brand or seller matches any keyword (case-insensitive). E.g. "LEGO", "toner", "Bose".

## `agencyName` (type: `string`):

Only return orders from agencies whose name contains this substring (case-insensitive). E.g. "NATURAL RESOURCES" or "LABOR AND INDUSTRIES".

## `productCategory` (type: `string`):

Only return line items whose Amazon product category contains this substring (case-insensitive). E.g. "Office Product", "Computer".

## `brand` (type: `string`):

Only return line items of this brand (case-insensitive). E.g. "HP", "Dell".

## `unspsc` (type: `string`):

Only return line items whose 8-digit UNSPSC commodity code starts with this. Accept 1/2/4/6/8 digits (8-digit = exact code). FY18 has no UNSPSC data and is skipped. E.g. "60141100", "6014", "44".

## `dateFrom` (type: `string`):

Only return orders on or after this date (YYYY-MM-DD). E.g. "2024-07-01".

## `dateTo` (type: `string`):

Only return orders on or before this date (YYYY-MM-DD). E.g. "2025-06-30".

## `minNetTotal` (type: `number`):

Only return line items whose net total (item + shipping + tax) is at or above this amount (USD). E.g. 500 for big-ticket orders.

## `fiscalYear` (type: `string`):

Only query this fiscal year's dataset. Blank = all FYs (FY18 is skipped automatically for UNSPSC filters, since that year predates the code).

## `aggregate` (type: `boolean`):

When on, returns one summary record per group (see groupBy) with total net spend and order count - instead of individual line items. Computed server-side, so it works over the whole corpus.

## `groupBy` (type: `string`):

Which dimension to aggregate over (only used when aggregate is on). E.g. 'agency' -> which agencies spend the most; 'productCategory' -> what categories dominate.

## `maxResults` (type: `integer`):

Cap the number of records pushed (0 = unlimited). A line-item query is capped by the run's charge cap; an aggregate query over the full corpus can reach thousands of groups.

## Actor input object example

```json
{
  "minNetTotal": 0,
  "fiscalYear": "",
  "aggregate": false,
  "groupBy": "agency",
  "maxResults": 200
}
```

# Actor output Schema

## `recordsUrl` (type: `string`):

Washington agency Amazon spend line items - agency, order date, product category/title, brand, UNSPSC, quantities and amounts - as JSON

## `datasetUrl` (type: `string`):

No description

## `runUrl` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("j0401/wa-amazon-spend").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("j0401/wa-amazon-spend").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call j0401/wa-amazon-spend --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,j0401/wa-amazon-spend"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/yjtNzphCvuwf4bVeB/builds/w8TkvxIAQkGljhTzz/openapi.json
