๐ณCredit Note (Avoir)
Learn how to generate and dispatch credit notes through Docs-Dispatcher with complete end-to-end examples in 4 languages (curl, Node.js, PHP, Java).
Overview
This comprehensive recipe walks you through the complete credit note generation and dispatch workflow:
Authenticate and set up Basic Authentication
Prepare your credit note data with original invoice reference
Validate the request (recommended safety check)
Send the credit note to your accounting provider
Handle the response and track status
By the end of this guide, you'll have working code to automatically generate and send credit notes (refunds, corrections, cancellations) to providers like Qonto, PennyLane, iPaidThat.
What You'll Learn
How to structure credit note requests for different providers
Reference original invoices correctly
Handle negative amounts and corrections
Best practices for validation before sending
Error handling strategies
Provider-specific credit note requirements
Complete working examples in 4 languages
Prerequisites
Before you begin:
Docs-Dispatcher account with email and password
At least one invoicing provider configured (Qonto, PennyLane, iPaidThat, or SuperPDP)
Template created in Templater (or use API to create one)
Original invoice ID/reference (the invoice you're crediting)
Basic understanding of REST APIs
No provider configured yet? You can still test with the validation endpoint - it checks your request format without calling external APIs or charging credits.
What is a Credit Note?
A credit note (avoir in French) is a document that:
Cancels all or part of an invoice
Refunds amounts already paid
Corrects errors in original invoices
Adjusts prices or quantities
Credits customer accounts
Common scenarios:
Product returned by customer
Service not delivered as agreed
Pricing error on original invoice
Quantity correction
Discount applied retroactively
Invoice cancellation
Step 1: Authentication
Dispatcher API uses HTTP Basic Authentication. You'll need your Dispatcher account email and password for all API calls.
Setup Credentials
No token management needed! Unlike JWT-based APIs, Basic Auth doesn't require separate authentication endpoints or token refresh. Your credentials are sent with each request.
Quick links:
Step 2: Prepare Credit Note Data
Structure your credit note data according to the CompositeRequest model. Credit notes require special fields to reference the original invoice.
Basic Credit Note Structure
Required Fields
providerName
string
Provider to use: qonto, pennylane, ipaidthat, superpdp
documentType
string
Must be CREDIT for credit notes
template.id
number
Template ID from Templater (use credit note template)
template.data
object
Template variables (schema depends on template)
invoicing.originalInvoiceId
string
Provider's invoice ID being credited
Credit Note Specific Fields
template.data.originalInvoice
object
Original invoice reference details
template.data.originalInvoice.number
string
Original invoice number
template.data.originalInvoice.id
string
Provider's invoice ID
template.data.reason
string
Reason for credit note
invoicing.creditReason
string
Structured reason code (see below)
Credit Reason Codes
PRODUCT_RETURN
Product returned by customer
Physical goods returned
SERVICE_NOT_DELIVERED
Service not provided
Service cancelled or incomplete
PRICING_ERROR
Error in original pricing
Wrong price charged
QUANTITY_ERROR
Quantity correction needed
Wrong quantity invoiced
DISCOUNT_APPLIED
Retroactive discount
Price adjustment after invoice
INVOICE_CANCELLATION
Full invoice cancellation
Complete cancellation
OTHER
Other reason
Custom scenarios
Partial vs Full Credit
Partial Credit (some items/amounts):
Full Credit (entire invoice):
Amounts in Credit Notes: Most providers expect positive amounts in credit notes (not negative). The document type CREDIT indicates these amounts should be subtracted from customer balance. Check your provider's specific requirements.
Step 3: Validate Request (Recommended)
Before sending real credit notes, validate your request structure. This checks for errors without calling external providers or charging credits.
Why Validate?
Catch errors early (before external API calls)
Verify original invoice reference is correct
Free and fast (< 100ms response)
No risk of duplicate credit notes
Test during development
Validation Request
Validation Success Response
Validation Error Response
Validation passed? You're ready to send the real credit note! Simply change /validate to /invoicing in the endpoint URL.
More on validation:
Step 4: Send Credit Note (Real Dispatch)
Once validation passes, send the actual credit note by changing the endpoint from /validate to /invoicing.
Sync Mode (Default)
Synchronous mode waits for the provider to complete the operation and returns the full response immediately.
Success Response:
When to use sync mode:
User is waiting for result (interactive workflows)
Quick operations (expected completion < 30 seconds)
Simple error handling (errors returned immediately)
Testing and development
Async Mode (Recommended for Production)
Asynchronous mode queues the request immediately and processes it in the background. You receive a webhook notification when complete.
Immediate Response:
More on execution modes:
Step 5: Handle Response
Process the dispatch response and handle errors gracefully.
Success Response Fields
success
true if dispatch succeeded
dispatchId
Unique dispatch identifier (use for tracking)
providerResponse.creditNoteId
Provider's credit note ID
providerResponse.originalInvoiceId
Original invoice reference
providerResponse.creditedAmount
Amount credited to customer
generatedDocument
Generated PDF document URL and metadata
metadata
Your custom tracking data (echoed back)
Error Response
Common Error Types
validation_error
Invalid request format
Check required fields
invoice_not_found
Original invoice doesn't exist
Verify invoice ID
invoice_already_credited
Invoice already has credit note
Check existing credits
credit_exceeds_invoice
Credit amount > invoice amount
Reduce credit amount
authentication_error
Invalid/expired JWT
Refresh token
provider_error
Provider API error
Check provider error details
Complete Examples
Here are complete, runnable examples in 4 languages showing the full credit note workflow from authentication to dispatch.
curl (Complete Flow)
Node.js (Complete Flow)
PHP (Complete Flow)
Java (Complete Flow)
Provider-Specific Notes
Different invoicing providers have unique credit note features and requirements.
Qonto
Provider name: qonto
Credit Note Features:
Full and partial credit notes supported
Automatic linking to original invoice
Customer notification optional
Sandbox mode available for testing
Specific requirements:
Original invoice ID required (Qonto's invoice ID)
Credit note number must be unique
Cannot exceed original invoice amount
Customer email required if sending notification
Example:
PennyLane
Provider name: pennylane
Credit Note Features:
Comprehensive credit note support
Automatic Chorus Pro submission for e-invoices
Detailed reason tracking
Multiple credit notes per invoice
Specific requirements:
Product codes required for credited items
Detailed reason documentation
SIRET required for French B2B credits
Tax breakdown must match original
Example:
iPaidThat
Provider name: ipaidthat
Credit Note Features:
Standard credit note support
Invoice reference tracking
Customer balance adjustment
Specific requirements:
Original invoice number required
Credit note must not exceed original amount
Customer email required
SuperPDP
Provider name: superpdp
Credit Note Features:
E-invoice compliant credit notes
Automatic archiving
Legal documentation trail
Specific requirements:
Complete original invoice reference
Detailed justification required
SIRET/SIREN for French companies
Provider Comparison
Credit Notes
โ
โ
โ
โ
Partial Credits
โ
โ
โ
โ
Multiple Credits
โ
โ
โ
โ ๏ธ Limited
E-Invoice Credits
โ
โ
โ
โ
Sandbox
โ
โ
โ
โ
Reason Tracking
โ
โ
โ
โ
Auto-linking
โ
โ
โ
โ
Error Handling
Common Credit Note Errors
1. Original Invoice Not Found
Cause: Invoice ID doesn't exist in provider
Solution:
Verify invoice ID is correct
Check invoice exists in provider
Ensure invoice belongs to same company
2. Credit Exceeds Invoice Amount
Cause: Credit total > original invoice total
Solution:
Reduce credit amount
Check calculation
Verify original invoice amount
3. Invoice Already Fully Credited
Cause: Invoice has already been fully credited
Solution:
Check existing credit notes
Calculate remaining crediteable amount
Adjust credit amount accordingly
Troubleshooting Common Issues
Issue 1: "Missing original invoice reference"
Symptoms:
Validation error on originalInvoiceId
Provider rejects credit note
Solutions:
Include
invoicing.originalInvoiceIdin requestUse provider's invoice ID (not your internal ID)
Verify invoice exists before crediting
Issue 2: "Credit amount calculation mismatch"
Symptoms:
Provider rejects due to amount inconsistency
Tax calculation errors
Solutions:
Ensure amounts are positive (not negative)
Match tax rates from original invoice
Use same rounding rules as invoice
Issue 3: "Duplicate credit note number"
Symptoms:
Provider error about existing credit note
Unique constraint violation
Solutions:
Use unique credit note numbers
Check existing credit notes first
Implement retry with new number
Next Steps
Now that you know how to generate and send credit notes:
Related Recipes
Invoice - Generate and send invoices
Quote - Create quotes before invoicing
Validate then Send - Production-ready validation pattern
Async Flow - Scale with webhooks
Core Concepts
Request Model - Understand CompositeRequest structure
Providers & Configurations - Configure providers
Services - Explore all services
Provider Documentation
Qonto - Qonto credit note features
PennyLane - PennyLane integration details
iPaidThat - iPaidThat configuration
SuperPDP - SuperPDP e-invoicing
Summary
You've learned how to:
โ Authenticate and obtain Basic Auth credentials
โ Structure credit note requests with original invoice references
โ Handle partial and full credits correctly
โ Validate requests before sending
โ Send credit notes in sync and async modes
โ Handle responses and errors gracefully
โ Implement complete workflows in 4 languages
โ Troubleshoot common credit note issues
Ready for production? Follow this checklist:
Configure your provider credentials
Create credit note templates in Templater
Validate all requests before dispatch
Implement error handling for invoice references
Track existing credits to prevent over-crediting
Use async mode for scalability
Monitor credit note success rates
Happy crediting!
Last updated