## Create credits by order ID

### cURL

```bash
curl --request POST \
  --url https://api.fabric.inc/v3/orders/{orderId}/actions/create-credits \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-fabric-channel-id: <x-fabric-channel-id>' \
  --header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
  --data '
{
  "credits": [
    {
      "amount": 21.5,
      "currency": "USD",
      "reasonCode": "EC",
      "source": "CSR",
      "type": "GIFT_CARD",
      "amountInCurrencies": [
        {
          "currency": "USD",
          "group": "SHOPPER",
          "amount": 123.45
        }
      ],
      "attributes": {
        "giftCardNumber": "XlQZTmFDFtPFGMxJP6oiAqN3vo+qKZ"
      },
      "employeeId": "12312232",
      "note": "Credit request initiated",
      "paymentCounter": 1,
      "policyCode": "RC1",
      "subReasonCode": "ACC"
    }
  ]
}
'  
```

### Python Example

```python
import requests

url = "https://api.fabric.inc/v3/orders/{orderId}/actions/create-credits"

payload = { "credits": [
        {
            "amount": 21.5,
            "currency": "USD",
            "reasonCode": "EC",
            "source": "CSR",
            "type": "GIFT_CARD",
            "amountInCurrencies": [
                {
                    "currency": "USD",
                    "group": "SHOPPER",
                    "amount": 123.45
                }
            ],
            "attributes": { "giftCardNumber": "XlQZTmFDFtPFGMxJP6oiAqN3vo+qKZ" },
            "employeeId": "12312232",
            "note": "Credit request initiated",
            "paymentCounter": 1,
            "policyCode": "RC1",
            "subReasonCode": "ACC"
        }
    ] }
headers = {
    "x-fabric-tenant-id": "<x-fabric-tenant-id>",
    "x-fabric-channel-id": "<x-fabric-channel-id>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### JavaScript Fetch Example

```javascript
const options = {
  method: 'POST',
  headers: {
    'x-fabric-tenant-id': '<x-fabric-tenant-id>',
    'x-fabric-channel-id': '<x-fabric-channel-id>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    credits: [
      {
        amount: 21.5,
        currency: 'USD',
        reasonCode: 'EC',
        source: 'CSR',
        type: 'GIFT_CARD',
        amountInCurrencies: [{currency: 'USD', group: 'SHOPPER', amount: 123.45}],
        attributes: {giftCardNumber: 'XlQZTmFDFtPFGMxJP6oiAqN3vo+qKZ'},
        employeeId: '12312232',
        note: 'Credit request initiated',
        paymentCounter: 1,
        policyCode: 'RC1',
        subReasonCode: 'ACC'
      }
    ]
  })
};

fetch('https://api.fabric.inc/v3/orders/{orderId}/actions/create-credits', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### PHP cURL Example

```php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.fabric.inc/v3/orders/{orderId}/actions/create-credits",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'credits' => [
        [
                'amount' => 21.5,
                'currency' => 'USD',
                'reasonCode' => 'EC',
                'source' => 'CSR',
                'type' => 'GIFT_CARD',
                'amountInCurrencies' => [
                                [
                                                                'currency' => 'USD',
                                                                'group' => 'SHOPPER',
                                                                'amount' => 123.45
                                ]
                ],
                'attributes' => [
                                'giftCardNumber' => 'XlQZTmFDFtPFGMxJP6oiAqN3vo+qKZ'
                ],
                'employeeId' => '12312232',
                'note' => 'Credit request initiated',
                'paymentCounter' => 1,
                'policyCode' => 'RC1',
                'subReasonCode' => 'ACC'
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "x-fabric-channel-id: <x-fabric-channel-id>",
    "x-fabric-tenant-id: <x-fabric-tenant-id>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

### Response Codes
- **200**: OK
- **400**: Bad request
- **401**: Unauthorized request
- **404**: Not found
- **500**: Internal server error

### Authorization

Authorization header must be in the format `Bearer <token>`.

#### Required Headers
- **x-fabric-tenant-id**: Identifier of the tenant.
- **x-fabric-channel-id**: Identifier for the sales channel.
