# Add a discount

`POST /shop/discounts` · Rivier · shop

Add a discount: a code or automatic, percent, fixed or free shipping, with limits.

- Scope: shop:admin
- Sdk: shop.discount.create
- Cli: shop discount create

## Request body

`application/json`

```json
{
  "type": "object",
  "properties": {
    "code": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{2,40}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "kind": {
      "type": "string",
      "enum": [
        "percent",
        "fixed",
        "free_shipping"
      ]
    },
    "percentBp": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000
        },
        {
          "type": "null"
        }
      ]
    },
    "amountMinor": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "currency": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[a-z]{3}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "scope": {
      "type": "object",
      "properties": {
        "all": {
          "type": "boolean"
        },
        "productIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          },
          "maxItems": 500
        },
        "collectionIds": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          },
          "maxItems": 50
        }
      },
      "additionalProperties": false,
      "default": {
        "all": true
      }
    },
    "minSubtotalMinor": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991,
      "default": 0
    },
    "limitTotal": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "limitPerContact": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "stackable": {
      "type": "boolean",
      "default": false
    },
    "automatic": {
      "type": "boolean",
      "default": false
    },
    "validFrom": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "validTo": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "name",
    "kind"
  ],
  "additionalProperties": false
}
```

## Responses

- `201`: Success
- `400`: The request was malformed
- `401`: No valid credential
- `403`: The credential lacks the scope, origin or address
- `429`: Over the key's rate limit; see Retry-After

## Example

```sh
curl -X POST 'https://api.rivier.ai/shop/discounts' \
  -H 'Authorization: Bearer $KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "string",
  "kind": "percent"
}'
```
