# The purchase links model

Source: https://developers.swell.is/backend-api/purchase-links/the-purchase-links-model

## Fields

- `id` (string, auto): The unique identifier for the purchase link. Default: `{"$formula":"alphanum(8)"}`.
- `name` (string, required): Human-friendly name of the purchase link.
- `active` (boolean, auto): The active status of the purchase link is automatically set to off and must be toggled on to activate, share, and use. Default: `false`.
- `coupon` (Coupon): Expandable link to the coupon applied to purchase link items.
- `coupon_id` (objectId): ID of the coupon applied to purchase link items.
- `currency` (string): Three-letter ISO currency code in uppercase. Defaults to your store's base currency.
- `date_created` (date, auto): Date the purchase link was created.
- `date_updated` (date, auto): Date the purchase link was last updated.
- `discount_total` (currency): Total discount amount.
- `discounts` (array of object): Discounts applied to purchase link items.
  - `id` (string): Unique identifier for the object.
  - `type` (string): Type of discount. Can be `coupon` or `promo-<id>` referring to the source of the discount. Custom discounts don't require this value.
  - `rule` (object): Object describing the discount rule details. Custom discounts don't require this value.
  - `amount` (currency): Fixed discount amount.
  - `source_id` (objectId)
- `grand_total` (currency, auto): Grand total including items, shipping, and taxes.
- `item_discount` (currency): Total discount applied to line items.
- `items` (array of object): List of line items describing the products ordered.
  - `id` (objectId, auto): Unique identifier for the item.
  - `quantity` (int): Quantity of the bundle item being ordered. Defaults to 1. Default: `1`.
  - `purchase_option` (object): Configuration of one or more purchase options for purchase link items. Can be standard for one-time purchases or subscription for a subscription plan. Products can support both purchase options simultaneously.
    - `type` (enum): Possible values: `standard`, `subscription`, `trial`.
    - `plan_id` (objectId): ID of the subscription plan.
  - `bundle_items` (array of object): List of items offered as a bundle. Defaults to `product.bundle_items`.
    - `id` (objectId): Unique identifier for the object.
    - `quantity` (int): Quantity of the bundle item being ordered. Defaults to 1. Default: `1`.
    - `product_id` (objectId, required): ID of the bundle item product.
    - `product` (product): Expandable link to the bundle item product.
    - `variant_id` (objectId): ID of the bundle item variant.
    - `variant` (variant): Expandable link to the bundle item variant.
    - `options` (array of object)
      - `id` (string): Unique identifier for the object.
      - `value` (string): Name value of the product option. When adding to the cart, specify either the product option value `id` or `name` (case-insensitive) to identify the value.
    - `amount_ratio` (float)
    - `price` (currency)
    - `discount_each` (currency)
    - `tax_each` (currency)
  - `product_id` (objectId): ID of product in the purchase link.
  - `product` (product): Expandable link to the product within the purchase link.
  - `variant_id` (objectId): ID of the product variant, if applicable.
  - `variant` (variant): Expandable link to the product variant.
  - `discount_total` (currency): Total discount applied to the item.
  - `discount_each` (currency): Total discount amount divided by quantity.
  - `metadata` (object): Arbitrary item data, typically set in a checkout flow to store custom values. See  [Storefront API](https://developers.swell.is/frontend-api/introduction) for details.
- `metadata` (object): Arbitrary data, typically set in a checkout flow to store custom values. See [Frontend API](https://developers.swell.is/frontend-api/introduction) for more details.
- `promotion_ids` (array of child_scalar): Array of promotion ids associated to the purchase link.
- `promotions` (Promotion): Link to promotions associated to the purchase link.
- `sub_total` (currency): The subtotal of all of the items in a purchase link.

## Example response

```json
{
  "active": true,
  "name": "Mythic Dawn Commentaries Collection",
  "items": [
    {
      "product_id": "628ba6011869c10019b41f70",
      "quantity": 1,
      "price": 60,
      "id": "628ba7241869c10019b41f7d",
      "orig_price": 60,
      "delivery": "shipment",
      "shipment_weight": 0,
      "price_total": 60,
      "discount_total": 0,
      "discount_each": 0
    },
    {
      "product_id": "628ba67a1869c10019b41f76",
      "quantity": 1,
      "price": 60,
      "id": "628ba728499bba0019b1a9c2",
      "orig_price": 60,
      "delivery": "shipment",
      "shipment_weight": 0,
      "price_total": 60,
      "discount_total": 0,
      "discount_each": 0
    },
    {
      "product_id": "628ba6b7499bba0019b1a9b2",
      "quantity": 1,
      "price": 60,
      "id": "628ba72b499bba0019b1a9c5",
      "orig_price": 60,
      "delivery": "shipment",
      "shipment_weight": 0,
      "price_total": 60,
      "discount_total": 0,
      "discount_each": 0
    },
    {
      "product_id": "628ba701499bba0019b1a9bb",
      "quantity": 1,
      "price": 60,
      "id": "628ba72d499bba0019b1a9c8",
      "orig_price": 60,
      "delivery": "shipment",
      "shipment_weight": 0,
      "price_total": 60,
      "discount_total": 0,
      "discount_each": 0
    }
  ],
  "shipment_delivery": true,
  "currency": "USD",
  "sub_total": 240,
  "item_discount": 0,
  "discount_total": 0,
  "grand_total": 240,
  "date_created": "2022-05-23T15:24:20.977Z",
  "date_updated": "2022-05-23T15:24:32.137Z",
  "id": "5wFVZQzV"
}
```
