> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nexudus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create ProductBookingCredit

> Create a new ProductBookingCredit record.

A **ProductBookingCredit** represents an amount of credit linked to a `Product`. When a customer purchases the product, the credit is automatically released as a `CoworkerBookingCredit` on the customer's account.

Credit can be configured for two primary uses:

* **Bookings** — set `CaneBeUsedForBookings` to allow the credit to pay for bookings. Use `ElegibleResourceTypes` to restrict the credit to specific resource types; if left empty the credit is valid for all resource types.
* **Events** — set `CaneBeUsedForEvents` to allow the credit to pay for event sign-ups. Use `EventCategories` to restrict to specific event categories; if left empty the credit is valid for all events.

Setting `IsUniversalCredit` enables the credit for products, time passes, and other charges. Use `ElegibleProducts`, `ElegiblePasses`, and `AppliesToCharges` to restrict which products or passes the credit is valid for. If all restriction lists are empty the universal credit applies to all products, passes and charges.

Use `ExpirationType` and `ExpiresIn` to control when the released credit expires.

## Authentication

<Note>
  This endpoint requires OAuth2 authentication. Include a valid bearer token in the `Authorization` header.
  The authenticated user must be a full unrestricted administrator or have the **`ProductBookingCredit-Create`** role.
</Note>

## Request Body

### Required Fields

<ParamField body="Name" type="string" required>
  Credit name.
</ParamField>

<ParamField body="ProductId" type="integer" required>
  Product Id.
</ParamField>

<ParamField body="Credit" type="number" required>
  Credit amount.
</ParamField>

### Optional Fields

<ParamField body="ElegibleResourceTypes" type="integer[]">
  Elegible Resource Types.
</ParamField>

<ParamField body="ElegibleProducts" type="integer[]">
  Elegible Products.
</ParamField>

<ParamField body="ElegibleTariffs" type="integer[]">
  Elegible Tariffs.
</ParamField>

<ParamField body="ExpireTimeInMonths" type="integer">
  Expire Time In Months.
</ParamField>

<ParamField body="ExpireTimeInWeeks" type="integer">
  Expire Time In Weeks.
</ParamField>

<ParamField body="CaneBeUsedForBookings" type="boolean">
  Whether this credit can be used to pay for bookings. Restrict to specific resource types with `ElegibleResourceTypes`.
</ParamField>

<ParamField body="CaneBeUsedForEvents" type="boolean">
  Whether this credit can be used to pay for event sign-ups. Restrict to specific categories with `EventCategories`.
</ParamField>

<ParamField body="EventCategories" type="integer[]">
  Event Categories.
</ParamField>

<ParamField body="ExpirationType" type="integer">
  Expiration type. See `eRecurrentChargePattern?` enum above.
</ParamField>

<ParamField body="ExpiresIn" type="integer">
  Number of periods (of `ExpirationType`) until the released credit expires.
</ParamField>

<ParamField body="IsUniversalCredit" type="boolean">
  Whether this is a universal credit applicable to products, time passes and other charges. Restrict with `ElegibleProducts`, `ElegiblePasses` and `AppliesToCharges`; if all are empty the credit applies to all products, passes and charges.
</ParamField>

<ParamField body="ElegiblePasses" type="integer[]">
  Elegible Passes.
</ParamField>

<ParamField body="AppliesToCharges" type="boolean">
  Whether this universal credit applies to other charges.
</ParamField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://spaces.nexudus.com/api/billing/productbookingcredits" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "Name": "",
      "ProductId": 0,
      "Credit": 0
  }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://spaces.nexudus.com/api/billing/productbookingcredits',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        Name: '',
        ProductId: 0,
        Credit: 0
      })
    }
  );

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://spaces.nexudus.com/api/billing/productbookingcredits',
      headers={
          'Authorization': 'Bearer YOUR_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'Name': '',
          'ProductId': 0,
          'Credit': 0
      }
  )

  data = response.json()
  ```
</CodeGroup>

## Response

### 200

<ResponseField name="Status" type="integer">
  HTTP status code. `200` on success.
</ResponseField>

<ResponseField name="Message" type="string">
  A human-readable message confirming the creation.
</ResponseField>

<ResponseField name="Value" type="object">
  Contains the `Id` of the newly created record.
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `true` if the productbookingcredit was created successfully.
</ResponseField>

<ResponseField name="Errors" type="array">
  `null` on success.
</ResponseField>

```json Example Response theme={null}
{
  "Status": 200,
  "Message": "ProductBookingCredit was successfully created.",
  "Value": {
    "Id": 87654321
  },
  "OpenInDialog": false,
  "OpenInWindow": false,
  "RedirectURL": null,
  "JavaScript": null,
  "UpdatedOn": "2025-01-15T10:30:00Z",
  "UpdatedBy": "admin@example.com",
  "Errors": null,
  "WasSuccessful": true
}
```

### 400

<ResponseField name="Message" type="string">
  A summary of the validation error(s), in the format `PropertyName: error message`.
</ResponseField>

<ResponseField name="Value" type="any">
  `null` on validation failure.
</ResponseField>

<ResponseField name="Errors" type="object[]">
  Array of validation errors.

  <Expandable>
    <ResponseField name="AttemptedValue" type="any">
      The value that was submitted for the field, or `null` if missing.
    </ResponseField>

    <ResponseField name="Message" type="string">
      The validation error message.
    </ResponseField>

    <ResponseField name="PropertyName" type="string">
      The name of the property that failed validation.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `false` when the request fails validation.
</ResponseField>

```json Example Response theme={null}
{
  "Message": "Name: is a required field",
  "Value": null,
  "Errors": [
    {
      "AttemptedValue": null,
      "Message": "is a required field",
      "PropertyName": "Name"
    }
  ],
  "WasSuccessful": false
}
```
