# Create a coupon code

Source: https://developers.swell.is/backend-api/coupon-codes/create-a-coupon-code

Create a new coupon code.

## Arguments

- `parent_id` (objectId, required): ID of the parent coupon.
- `id` (objectId): ID of the coupon code.
- `code` (string): Unique code to identify the coupon.
- `date_created` (date, auto): Date and time the coupon code was created.
- `date_updated` (date, auto): Date and time the coupon code was last updated.
- `gen_id` (objectId): The ID of the generation instance for a particular coupon code.
- `orders` (Order)
- `parent` (Coupon): Expandable link to the parent coupon.
- `subscriptions` (Subscription)
- `use_count` (int)
- `use_total` (int): Default: `0`.

## Example request

`POST /coupons:codes`

**cURL**

```sh
$ curl https://api.swell.store/coupons:codes \
  -u store-id:secret-key \
	-d code:"ALCHEMY25" \
	-d parent_id:62cc86897ad4f100132c953d \
```

**Node**

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

await swell.post('/coupons:codes', {
code: 'ALCHEMY25',
parent_id: '62cc86897ad4f100132c953d'
});
```

**PHP**

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

$swell->post('/coupons:codes', [
'code' => 'ALCHEMY25',
'parent_id' => '62cc86897ad4f100132c953d'
]);
```

## Example response

```json
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}
```
