# Bee Pre Order API

Pre-orders with partial payment, and back in stock alerts, for one Shopify
shop. Every request acts for the shop the token belongs to; there is no way to
name a different one.

## Authenticating

Send the token from the app's Settings page:

    Authorization: Bearer bpo_...

A token that is missing, wrong or revoked gets 401. Nothing in a response says
whether a token exists, only whether this one works.

## Reading

    GET http://bpo.beecreative.pk/api/v1/shop
    GET http://bpo.beecreative.pk/api/v1/campaigns
    GET http://bpo.beecreative.pk/api/v1/campaigns/{id}
    GET http://bpo.beecreative.pk/api/v1/restock/settings
    GET http://bpo.beecreative.pk/api/v1/restock/waiting
    GET http://bpo.beecreative.pk/api/v1/balances

## Writing

    POST  http://bpo.beecreative.pk/api/v1/campaigns
    PATCH http://bpo.beecreative.pk/api/v1/campaigns/{id}
    PATCH http://bpo.beecreative.pk/api/v1/restock/settings

A campaign write goes to Shopify first and is only saved if Shopify accepts
it, so a 2xx means the purchase option is really live on the storefront.

### A campaign

    {
      "name": "Winter drop",
      "status": "ACTIVE",                     // or PAUSED
      "paymentMode": "PARTIAL",               // PARTIAL | FULL | BOTH
      "deposit": { "type": "PERCENTAGE", "percent": 20 },
      // or:     { "type": "AMOUNT", "amount": 50 }
      "balance": { "trigger": "EXACT_TIME", "dueAt": "2026-10-21" },
      // or:    { "trigger": "TIME_AFTER_CHECKOUT", "dueAfterDays": 30 },
      // or:    { "trigger": "NONE" }          // only when paying in full
      "discount": { "type": "PERCENTAGE", "value": 10 },
      // PERCENTAGE | AMOUNT | PRICE, or null for none
      "shipping": {
        "trigger": "EXACT_TIME",              // ASAP | EXACT_TIME | UNKNOWN
        "expectedShipAt": "2026-12-01",
        "reduceStock": "ON_SALE"              // ON_SALE | ON_FULFILLMENT
      },
      "schedule": { "startsAt": null, "endsAt": "2026-11-30", "countdown": true },
      "onlyWhenSoldOut": false,
      "maxUnits": 10,                         // or null for no limit
      "variants": [
        {
          "productId": "gid://shopify/Product/123",
          "variantId": "gid://shopify/ProductVariant/456"
        }
      ]
    }

Only the fields you send are changed; the rest keep their current values.
Sending "variants" replaces the whole list, so include every variant that
should stay on the campaign.

### Back in stock settings

    {
      "enabled": true,
      "buttonVisibility": "OUT_OF_STOCK",     // OUT_OF_STOCK | ALWAYS | NEVER
      "doubleOptIn": false,
      "minStock": 1,
      "batchSize": 50,
      "batchWaitMinutes": 10,
      "reminderEnabled": false,
      "reminderHours": 24,
      "orderTag": "back-in-stock"
    }

## When something is refused

    400  the body wasn't JSON
    401  the token is missing, wrong or revoked
    404  no campaign with that id
    405  that method isn't allowed on that path
    409  another campaign already holds one of those variants, or the shop's
         Shopify session has expired and the merchant must open the app once
    422  a field was rejected; "details" says which, keyed by field name

## Rules worth knowing before writing

- One active campaign per variant. A second one is refused with 409 rather
  than quietly taking the variant over.
- A deposit of 100% is a pre-order paid in full, so it has no balance.
- A fixed deposit must be less than the price of every product on the
  campaign, or Shopify refuses the order at checkout.
- Dates are plain calendar days ("2026-10-21"). The balance date must be
  after today; a ship date may be today.
- Pausing a campaign removes the pre-order option from carts that already
  hold it, so those shoppers would pay full price. Orders already placed are
  never affected.
