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

# Apply a credit note to invoices

> Spends a credit note against one or more invoices and returns the credit note.

Applies the credit note to each invoice listed under `credit_note.invoices`, each entry with only `invoice_id` and `amount`. It records a payment against each invoice and a journal posting, and returns the credit note.

> [!NOTE]
>
> The SDK samples get their client from credentials your app registers once when it starts, as shown in [Authentication](https://exsited.mintlify.site/authentication.md#set-up-a-client). To try the call here, click **Try it**, set `host` to your Exsited API host name and paste an access token from [Get an access token](https://exsited.mintlify.site/api-reference/authentication/get-an-access-token.md). To send a raw JSON body instead of filling in fields, copy the cURL sample and edit its `-d` payload.


## OpenAPI

````yaml POST /credit_notes/{credit_note_id}/apply
openapi: 3.1.0
info:
  title: Exsited API
  version: v4
servers:
  - url: https://{host}/api/v4
    variables:
      host:
        default: your-api-host.example.com
        description: Your Exsited API host name, without https://.
security:
  - bearerAuth: []
tags:
  - name: Authentication
  - name: Accounts
  - name: Account emails
  - name: Account groups
  - name: Communications
  - name: Communication profiles
  - name: Orders
  - name: Quote orders
  - name: Express
  - name: Usages
  - name: Sales reps
  - name: Gift certificates
  - name: Invoices
  - name: Pro-forma invoices
  - name: Payments
  - name: Refunds
  - name: Credit notes
  - name: Credit note applications
  - name: Reconciliations
  - name: Items
  - name: Inventory adjustments
  - name: Units of measurement
  - name: Zones
  - name: Shipping packages
  - name: Shipping rules
  - name: Fulfillment profiles
  - name: Fulfillment terms
  - name: Item fulfillments
  - name: Item receipts
  - name: Bookings
  - name: Rental assets
  - name: Return merchandise authorisations
  - name: Purchase orders
  - name: Purchase invoices
  - name: Purchase payments
  - name: Purchase refunds
  - name: Purchase credit notes
  - name: Purchase credit note applications
  - name: Purchase express
  - name: Return vendor authorizations
  - name: ABA files
  - name: Receive terms
  - name: Labours
  - name: Tasks
  - name: Timesheets
  - name: Milestones
  - name: Employees
  - name: Departments
  - name: Designations
  - name: Teams
  - name: Time periods
  - name: Workflows
  - name: Workflow settings
  - name: Events
  - name: Custom events
  - name: System events
  - name: Approvals
  - name: Approval profiles
  - name: Approval user groups
  - name: Alerts
  - name: Alert responsibility settings
  - name: Alert responsibilities
  - name: Action scripts
  - name: Note groups
  - name: Note attachments
  - name: Instance settings
  - name: Accounting codes
  - name: Additional codes
  - name: Billing periods
  - name: Charging periods
  - name: Pricing periods
  - name: Invoice terms
  - name: Days of the month
  - name: Countries
  - name: Salutations
  - name: Document templates
  - name: Email templates
  - name: Roles
  - name: Operators
  - name: Operator groups
  - name: User settings
  - name: Custom attributes
  - name: Custom components
  - name: Custom features
  - name: Custom fields
  - name: Custom forms
  - name: Attribute attachments
  - name: Portal
  - name: Integration connections
  - name: External databases
  - name: Reports
  - name: Applications
  - name: Organisation
  - name: Child organisations
  - name: Webhooks
paths:
  /credit_notes/{credit_note_id}/apply:
    post:
      tags:
        - Credit notes
      summary: Apply a credit note to invoices
      description: >-
        Applies the credit note to each invoice listed under
        `credit_note.invoices`, each entry with only `invoice_id` and `amount`.
        It records a payment against each invoice and a journal posting, and
        returns the credit note.
      operationId: credit_notes_apply_credit_note
      parameters:
        - name: credit_note_id
          in: path
          required: true
          description: The credit note's `id`, which starts with `cn_`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                credit_note:
                  type: object
                  properties:
                    invoices:
                      type: array
                      items:
                        type: object
                        properties:
                          invoice_id:
                            type: string
                          amount:
                            type: number
              required:
                - credit_note
            example:
              credit_note:
                invoices:
                  - invoice_id: INV-0001
                    amount: 5
      responses:
        '200':
          description: The credit note after the application.
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -X POST
            "$EXSITED_BASE_URL/api/v4/credit_notes/cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d/apply"
            \
              -H "Authorization: Bearer $ACCESS_TOKEN" \
              -H "Content-Type: application/json" \
              -d '{
                "credit_note": {
                  "invoices": [
                    {
                      "invoice_id": "INV-0001",
                      "amount": 5
                    }
                  ]
                }
              }'
        - lang: python
          label: Python
          source: |
            from exsited import build_client

            client = build_client()

            response = client.credit_notes.apply_credit_note(
                "cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d",
                {"credit_note": {"invoices": [{"invoice_id": "INV-0001", "amount": 5}]}},
            )
            print(response.data)
        - lang: javascript
          label: JavaScript
          source: >
            import {buildClient} from 'exsited';


            const client = await buildClient();


            const response = await
            client.creditNotes.applyCreditNote('cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d',
            {
                credit_note: {invoices: [{invoice_id: 'INV-0001', amount: 5}]},
            });

            console.log(response.data);
        - lang: php
          label: PHP
          source: >
            use Exsited\Client\ClientRegistry;


            $client = ClientRegistry::buildClient();


            $response =
            $client->creditNotes->applyCreditNote('cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d',
            [
                'credit_note' => ['invoices' => [['invoice_id' => 'INV-0001', 'amount' => 5]]],
            ]);

            print_r($response->data);
        - lang: java
          label: Java
          source: |
            import com.exsited.Dto;
            import com.exsited.client.ApiResponse;
            import com.exsited.client.ClientRegistry;
            import com.exsited.client.ExsitedClient;
            import java.util.List;
            import java.util.Map;

            ExsitedClient client = ClientRegistry.buildClient();

            ApiResponse<Dto> response = client.creditNotes().applyCreditNote(
                    "cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d",
                    Map.of(
                            "credit_note", Map.of(
                                    "invoices", List.of(Map.of("invoice_id", "INV-0001", "amount", 5)))));
            System.out.println(response.getMap());
        - lang: csharp
          label: .NET
          source: |
            using Exsited.Client;

            await using var client = ExsitedClient.BuildClient();

            var response = await client.CreditNotes.ApplyCreditNoteAsync(
                "cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d",
                new Dictionary<string, object?>
                {
                    ["credit_note"] = new Dictionary<string, object?>
                    {
                        ["invoices"] = new List<object?>
                        {
                            new Dictionary<string, object?>
                            {
                                ["invoice_id"] = "INV-0001",
                                ["amount"] = 5,
                            },
                        },
                    },
                });

            Console.WriteLine(response.Json);
        - lang: dart
          label: Dart
          source: |
            import 'package:exsited/exsited.dart';

            final client = buildClient();

            final response = await client.creditNotes.applyCreditNote(
              'cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d',
              {
                'credit_note': {
                  'invoices': [
                    {'invoice_id': 'INV-0001', 'amount': 5},
                  ],
                },
              },
            );
            print(response.map);
        - lang: go
          label: Go
          source: "import (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\texsited \"github.com/exsited/exsited-sdk-go/v4\"\n)\n\nclient, err := exsited.BuildClient(nil)\nif err != nil {\n\tlog.Fatal(err)\n}\ndefer client.Close()\n\nresponse, err := client.CreditNotes().ApplyCreditNote(context.Background(), \"cn_8a1d2c3b4e5f4a6b9c7d0e1f2a3b4c5d\", map[string]any{\n\t\"credit_note\": map[string]any{\n\t\t\"invoices\": []any{\n\t\t\tmap[string]any{\"invoice_id\": \"INV-0001\", \"amount\": 5},\n\t\t},\n\t},\n}, nil)\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Println(response.Map)\n"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        An access token from `POST /api/v4/oauth2/token`. The SDKs get and renew
        it for you.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.