# Create a promotion

Source: https://developers.swell.is/backend-api/promotions/create-a-promotion

Create a new promotion.

## Arguments

- `name` (string, required): A short descriptive name of the promo.
- `description` (string): A brief description of the promo, as it may be displayed to customers.
- `active` (boolean): Indicates the promo is currently active. Note: this is not affected by `date_start` and `date_end`. Default: `false`.
- `date_start` (date): Date the promo is first available. When defined, the promo will not be valid until after this date and before `date_end`.
- `date_end` (date): Date the promo ends and is no longer available. When defined, the promo will not be applied after this date.
- `discounts` (array of object, required): List of discount rules to apply.
  - `type` (enum): Type of discount to apply. Can be `total`, `product`, `category`, or `shipment`. Possible values: `total`, `shipment`, `product`, `category`, `buy_get`. Default: `"total"`.
  - `value_type` (enum, required): Type of discount amount to calculate. Can be `fixed` or `percent`. Possible values: `fixed`, `percent`. Default: `"fixed"`.
  - `value_fixed` (currency): Fixed discount applied when `value_type=fixed`.
  - `value_percent` (float): Percentage discount applied when `value_type=percent`.
  - `total_min` (currency): Minimum order total required for the rule to apply.
  - `discount_max` (currency): The maximum amount of a discount that can be redeemed.
  - `price_min` (currency): The minimum amount of a discount that can be redeemed.
  - `quantity_min` (int): Minimum product quantity required for the rule to apply, applicable for category and product discounts.
  - `quantity_max` (int): Maximum product quantity for which the rule will apply, applicable for category and product discounts.
  - `product_id` (objectId): ID of the product to discount, if applicable.
  - `variant_id` (objectId): ID of the variant to discount, if applicable.
  - `shipment_service` (string): ID of the shipping service to discount, if applicable.
  - `category_id` (objectId): ID of the category to discount, if applicable.
  - `exclude_category_ids` (array of child_scalar): List of category IDs to exclude from discount, applicable to category discounts when several categories overlap.
  - `product` (product): Expandable link to the discounted product, if applicable.
  - `variant` (variant): Expandable link to the discounted variant, if applicable.
  - `category` (category): Expandable link to the discounted category, if applicable.
  - `exclude_categories` (exclude_categories): Expandable list of excluded categories, if applicable.
  - `buy_items` (array of object): Items required to be purchased in order to receive the promotion.
    - `product_id` (objectId): ID of the product that is tied to the promotion eligibility, if applicable.
    - `product` (product): Expandable link to the promotion-eligible product, if applicable.
    - `category_id` (objectId): ID of the category that is tied to the promotion eligibility, if applicable.
    - `category` (category): Expandable link to the promotion-eligible category, if applicable.
  - `get_items` (array of object): Eligible discounted items available once  promotion's `buy_items` requirements are met.
    - `product_id` (objectId): ID of the product to discount, if applicable.
    - `product` (product): Expandable link to the discounted product, if applicable.
    - `category_id` (objectId): ID of the discounted category, if applicable.
    - `category` (category): Expandable link to the discounted category, if applicable.
- `use_count` (int): Number of times the promo has been applied. Default: `0`.
- `limit_uses` (int): Maximum number of times the promo will be applied across all customers.
- `limit_account_uses` (int): Maximum number of times the promo will be applied by each customer account.
- `limit_account_groups` (array of child_scalar): List of customer account for which the promo will apply.
- `discount_group` (string): ID of the discount group the promo belongs to, if applicable, as defined in discount settings. Used to ensure only one set of discount rules can apply across a number of coupons and promotions.
- `exclusions` (array of object): List of exclusions considered when the promo is applied.
  - `type` (enum, required): The type of exclusion for the promotion. Can be either `product` or `category`. Possible values: `product`, `category`.
  - `product_id` (objectId): ID of the product to exclude from the discount, if applicable.
  - `category_id` (objectId): ID of the category to exclude from the discount, if applicable.
  - `product` (product): Expandable link to the excluded product, if applicable.
  - `category` (category): Expandable link to the excluded category, if applicable.
- `uses` (Promotion Use): Expandable list of promo usage records.
- `orders` (Order): Expandable list of orders that have applied the promo.
- `subscriptions` (Subscription): Expandable list of subscriptions that have applied the promo.
- `currency` (string): Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
- `limit_account_segments` (array of child_scalar)

## Example request

`POST /promotions`

**cURL**

```bash
$ curl https://api.swell.store/promotions \
  -u store-id:secret-key \
  -d discounts[0][type]=total \
  -d discounts[0][value_type]=percent \
  -d discounts[0][value_fixed]=15 \
  -d name="15% Off Store Wide Sale" \
  -d active=true \
  -d date_end=2018-03-01T00:00:00.000Z \
  -d date_start=2018-11-01T00:00:00.000Z \
  -d description="Save 15% store wide for a limited time only." \
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.post('/promotions', {
  discounts: [
    {
      type: 'total',
      value_type: 'percent',
      value_fixed: 15
    }
  ],
  name: '15% Off Store Wide Sale',
  active: true,
  date_end: '2018-03-01T00:00:00.000Z',
  date_start: '2018-11-01T00:00:00.000Z',
  description: 'Save 15% store wide for a limited time only.'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->post('/promotions', [
  'discounts' => [
    [
      'type' => 'total',
      'value_type' => 'percent',
      'value_fixed' => 15
    ]
  ],
  'name' => '15% Off Store Wide Sale',
  'active' => true,
  'date_end' => '2018-03-01T00:00:00.000Z',
  'date_start' => '2018-11-01T00:00:00.000Z',
  'description' => 'Save 15% store wide for a limited time only.'
]);
```

## Example response

```json
{
  "id": "60f199509111e7000000006b",
  "name": "15% Off Store Wide Sale",
  "active": true,
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.386Z",
  "date_end": "2018-03-01T00:00:00.000Z",
  "date_start": "2018-11-01T00:00:00.000Z",
  "date_updated": "2021-07-16T14:36:00.386Z",
  "description": "Save 15% store wide for a limited time only.",
  "discounts": [
    {
      "type": "total",
      "value_type": "percent",
      "value_fixed": 15
    }
  ],
  "limit_account_uses": 3,
  "limit_uses": 300,
  "use_count": 142
}
```
