# Create an account credit

Source: https://developers.swell.is/backend-api/account-credits/create-an-account-credit

Create a new customer account credit.

## Arguments

- `amount` (currency, required): Account credit value. Must be greater than zero.
- `parent_id` (objectId, required): Unique identifier for the parent account.
- `id` (objectId): Unique identifier for the account credit.
- `number` (string): Automatically generated field that gets incremented each time an account credit is created.
- `credit` (Account credit): Expandable list of account credits.
- `credit_id` (objectId): ID of the credit applied to the customer's account.
- `currency` (string): Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
- `date_created` (date, auto): Date and time the credit was created.
- `date_updated` (date, auto): Date and time the credit was last updated.
- `giftcard_id` (objectId): ID of the gift card used to make the payment, if applicable.
- `invoice` (Invoice): Expandable link to the invoice the credit was applied to, if applicable.
- `invoice_id` (objectId): ID of the invoice the credit was applied to, if applicable.
- `parent` (Account): Expandable link to the parent account.
- `payment` (Payment): Expandable link to the payment.
- `payment_id` (objectId): Unique identifier for the payment.
- `reason` (string): The reason for the refund.
- `reason_message` (string): A brief message describing the reason for the refund.
- `refund` (Refund): Expandable list of refunds that apply to the credit.
- `refund_id` (objectId): ID of the refund the credit was applied to.

## Example request

`POST /accounts:credits`

**cURL**

```sh
$ curl https://api.swell.store/accounts:credits \
  -u store-id:secret-key \
  -d parent_id=621e53a6213eaf013d1fa6b2 \
  -d amount=17 \
  -d reason=refund
```

**Node**

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

await swell.post('/accounts:credits', {
  parent_id: '621e53a6213eaf013d1fa6b2',
  amount: 17,
  reason: 'refund'
});
```

**PHP**

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

$swell->post('/accounts:credits', [
  'parent_id' => '621e53a6213eaf013d1fa6b2',
  'amount' => 17,
  'reason' => 'refund'
]);
```

## Example response

```json
{
  "parent_id": "621e53a6213eaf013d1fa6b2",
  "amount": 17,
  "reason": "refund",
  "currency": "USD",
  "date_created": "2022-07-08T20:27:40.199Z",
  "number": "100003",
  "id": "62c8933c5f4ffe00136039f2"
}
```
