# VendHub lead feed: build instructions for your coding agent

You are connecting this company's vending listings to the VendHub directory. Build exactly what is described here. Do not design a different flow. If this codebase cannot support a step, stop and ask the person you are working with.

## What you are building

A small sync that sends every new, changed and removed listing to one VendHub endpoint. Operators browse the listings on VendHub, and each click goes to the listing page on this company's site.

- Endpoint: `POST https://www.vendhubhq.com/api/vendlead/partner-feed`
- Auth header: `Authorization: Bearer <key>`
- Use the `www` host exactly as written. The bare domain redirects, and many HTTP clients drop the POST or the auth header on a redirect.
- Full docs: https://www.vendhubhq.com/lead-partners#api

## Before you write code

Ask the person you are working with for these if you cannot find them:

1. **The API key.** It starts with `vlp_`. If they have none, they sign up at https://www.vendhubhq.com/lead-partners with an email at the company's own domain, and the key is emailed there after approval. You can build and unit test without it, but you need it for step 3 below.
2. **Where listings are stored,** and how to tell when one is created, changed, sold or removed.
3. **Which listings they have the right to share.** Send only real, current US vending listings.

Store the key in an environment variable named `VENDLEAD_KEY`. Never commit it, log it or send it to a browser. This job runs on the server only.

## Step 1: map each listing

Write one function that turns a listing into this shape. Send only the fields below: any other field gets the listing rejected.

| Field | Rules |
|---|---|
| `id` | Required. Your listing id. Sending it again updates the listing. |
| `url` | Required. The listing page on your site (https, your domain). Buyers land here. |
| `type` | Required. location, route, business_for_sale or machine. |
| `state, city` | US state (code or name) and city. Or send lat and lng. |
| `property_type` | Optional. Venue type: office, gym, hotel, apartment and so on. |
| `price, price_period` | Optional. USD; one_time, monthly or negotiable. |
| `annual_revenue` | Optional. Routes and businesses. |
| `published_at` | Optional. When the listing went live on your site: 2026-10-01 or 2026-10-01T14:00:00Z. |
| `status` | Optional, new. active, pending, sold or withdrawn. Sold and withdrawn listings come down. |
| `updated_at` | Optional, new. When you last changed the listing (2026-10-01T14:00:00Z). An update older than the last one we stored is ignored and listed in stale. |
| `annual_cash_flow` | Optional, new. Yearly net. Must not be more than annual_revenue. |
| `revenue_basis` | Optional, new. gross or net: what annual_revenue measures. |
| `machine_count, location_count` | Optional, new. Whole numbers. |
| `rights_basis` | Optional, new. owned, contract, verbal or none: what backs each placement. |
| `photo_url` | Optional, new. https URL of a real photo of the site that you have the rights to share. VendHub downloads and re-hosts it within about 10 minutes; send a new URL to replace it. JPG, PNG or WebP, under 10 MB. No people, faces, logos or text overlays. |
| `mode (top level)` | Optional, new. delta (default) or full. Full means this request is your whole active set: your live listings missing from it come down. |
| `Never send` | phone, email, seller_name, address or business_name. A listing with any of them is rejected (contact_data_not_accepted). |

Also enforced:

- `id`: 1 to 120 characters, letters, digits and `. _ : -` only. Use a stable id that never changes for a listing.
- `url`: https, on the company's approved domain or a subdomain of it. Each url belongs to one id.
- Location: send `state` or both `lat` and `lng`. `lat` and `lng` always go together.
- Money is a JSON number in USD, not a string like "$450".
- `updated_at` needs a full timestamp with a timezone. `published_at` also accepts a plain date.
- Leave out a field you do not have. Do not send null or an empty string.

Example listing:

```json
{
  "id": "12345",
  "url": "https://yoursite.com/listings/12345",
  "type": "location",
  "city": "Austin",
  "state": "TX",
  "property_type": "office",
  "price": 450,
  "price_period": "one_time",
  "status": "active",
  "updated_at": "2026-11-02T14:00:00Z"
}
```

## Step 2: build the sync

Send changes when they happen if this system has a hook or event for it. Otherwise run a job every 15 minutes that sends what changed since its last successful run.

Request body, with only these three top-level keys:

```json
{ "listings": [ ], "removed": ["12001"], "mode": "delta" }
```

- Always send `updated_at`, so an older retry cannot overwrite a newer update.
- Sold or taken down: put the id in `removed`, or send the listing with `status` set to `sold` or `withdrawn`.
- At least one listing or removed id per request. An id can appear only once per request, across `listings` and `removed` together.
- Limits: 500 listings, 500 removed ids and 1 MB per request, 120 requests an hour. Split larger sets into batches.
- First run: send every active listing, in batches.
- Use `"mode": "full"` only for a nightly cleanup, and only if all active listings fit in one request. Live listings missing from a full request come down. With more than 500 active listings, never use it: it would remove everything outside that batch.

Handle responses like this:

| Status | What to do |
|---|---|
| `200` | Check `rejected`. Log each id and error and flag it for a person; do not resend it unchanged. `stale` ids were older than what we hold, so ignore them. The rest applied. |
| `400` | Nothing applied. The error names the field. Log it and fix the mapping; do not retry unchanged. A url already used by another id must go in `removed` first. |
| `401` | Stop and alert a person. The key is wrong or suspended. |
| `413` | Split the batch and resend. |
| `429` | Wait, then resend with backoff. Send larger batches less often. |
| `500` | Retry with exponential backoff. Repeating a request is safe: sending the same listing again updates it. |

## Step 3: test against the live endpoint

Run these in order with the real key. Do not skip to publishing.

1. **Check the key.** `GET https://www.vendhubhq.com/api/vendlead/partner-feed` with the auth header returns the company name and `live_listings`.
2. **Dry run.** `POST https://www.vendhubhq.com/api/vendlead/partner-feed?dry_run=1` with a batch of real listings runs every check and publishes nothing. Fix the mapping until `rejected` is empty.
3. **One real listing.** Send one without `dry_run`, then repeat the key check and confirm `live_listings` went up.
4. **One removal.** Send the same id in `removed` and confirm the count goes back down.
5. **Full run.** Send all active listings, then turn on the sync.

```bash
curl -X POST https://www.vendhubhq.com/api/vendlead/partner-feed \
  -H "Authorization: Bearer $VENDLEAD_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "listings": [
    {
      "id": "12345",
      "url": "https://yoursite.com/listings/12345",
      "type": "location",
      "city": "Austin",
      "state": "TX",
      "property_type": "office",
      "price": 450,
      "price_period": "one_time",
      "status": "active",
      "updated_at": "2026-11-02T14:00:00Z"
    }
  ],
  "removed": [
    "12001"
  ]
}'
```

## Step 4: report back

Tell the person you are working with, so they can pass it to VendHub:

- How many listings were sent, accepted and rejected, and why any were rejected.
- The final `live_listings` count.
- How often the sync runs, and who gets alerted when it fails.

## What VendHub does with the data

VendHub publishes facts only: type, city and state, venue type and price. It writes its own titles and never copies descriptions. A `photo_url` you send is downloaded, resized and hosted by VendHub; VendHub never links to your copy. Seller contact details and full addresses must never be sent.

If this company cannot push, ask them to contact VendHub about a pull feed: a URL returning `{"listings": [...]}` with the same fields, which VendHub fetches every hour. Listings missing from it come down.
