Invoice API Usage Guide
API Version: v1.0
Microservice: XDPeople.Soba.Invoice.WebAPI
Overviewβ
The Invoice API is an XDPeople.Soba microservice responsible for complete lifecycle management of sales documents, including:
- π Quotes
- π¦ Orders
- π Proforma Invoices
- π§Ύ Sales Invoices
- π° Receipts
- β©οΈ Credit Notes
Key Featuresβ
- β Document creation, update, and query
- β Advanced filters (status, dates, customer, document type)
- β Result pagination
- β JWT authentication
- β Multi-tenancy support
- β Clean Architecture with CQRS pattern
- β Swagger/OpenAPI documentation
Technical Informationβ
Base URLβ
| Environment | Base URL | Documentation |
|---|---|---|
| Production | https://api.xdsoba.com/invoice/api/v1 | Swagger UI |
For local development environments, please refer to the internal configuration documentation.
Technologies Usedβ
- .NET 8.0 - Main framework
- MediatR - CQRS pattern implementation
- Entity Framework Core - Data access ORM
- MySQL - Main database
- FluentValidation - Command validation
- JWT Bearer Authentication - Authentication
- Swagger/OpenAPI - API documentation
Health Checksβ
GET /health
Checks API status (memory, connectivity, etc.)
Authenticationβ
The Invoice API uses JWT (JSON Web Token) for authentication.
Obtain JWT Tokenβ
To obtain a JWT token, use the Gateway authentication endpoint:
POST https://api.xdsoba.com/gateway/auth/combined-login
Content-Type: application/json
{
"tenantKey": "XDPT.30010",
"tenantPassword": "your-tenant-password",
"userKey": "user@example.com",
"userPassword": "your-user-password"
}
Use the Tokenβ
Add the token to the Authorization header of all requests:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Authentication in Swagger UIβ
- Access the Swagger UI
- Click the "Authorize" button (π)
- Enter:
Bearer <your-jwt-token> - Click "Authorize"
- Close the modal
Available Endpointsβ
1. Create Documentβ
POST /api/v1/invoices
Content-Type: application/json
Authorization: Bearer {token}
Description: Creates a new sales document (invoice, quote, order, etc.)
Response Codes:
201 Created- Document created successfully400 Bad Request- Invalid data401 Unauthorized- Not authenticated500 Internal Server Error- Internal error
2. Update Documentβ
PUT /api/v1/invoices/{id}
Content-Type: application/json
Authorization: Bearer {token}
Description: Updates an existing document
Response Codes:
200 OK- Document updated successfully400 Bad Request- Invalid data or ID mismatch404 Not Found- Document not found409 Conflict- Concurrency conflict500 Internal Server Error- Internal error
3. Get Document by IDβ
GET /api/v1/invoices/{id}
Authorization: Bearer {token}
Description: Gets the complete details of a document by its ID
Response Codes:
200 OK- Document found404 Not Found- Document not found
4. Get Document by Numberβ
GET /api/v1/invoices/{documentTypeId}/{serieId}/{number}
Authorization: Bearer {token}
Description: Gets a document by its type, series, and number
Parameters:
documentTypeId(int) - Document type IDserieId(int) - Series IDnumber(int) - Document number
Response Codes:
200 OK- Document found400 Bad Request- Invalid parameters404 Not Found- Document not found
5. List Documentsβ
GET /api/v1/invoices?pageNumber=1&pageSize=10&status=Open&fromDate=2025-01-01&toDate=2025-12-31
Authorization: Bearer {token}
Description: Lists documents with optional filters and pagination
Query Parameters:
pageNumber(int, default: 1) - Page numberpageSize(int, default: 10) - Page sizestatus(string, optional) - Filter by status (Open/Closed)fromDate(DateTime, optional) - Start creation date (format: YYYY-MM-DD)toDate(DateTime, optional) - End creation date (format: YYYY-MM-DD)entityKeyId(string, optional) - Filter by customer/supplierdocumentTypeId(int, optional) - Filter by document typesortBy(string, optional) - Sort by field (date/number/entity/total)sortDescending(bool, default: false) - Descending order
Response Codes:
200 OK- Document list returned successfully
Main Featuresβ
1. Sales Document Managementβ
The Invoice API supports all sales document types:
| Document Type | Description | Typical Use | Dedicated Guide |
|---|---|---|---|
| Quote | Quote | Commercial proposals | π Quotes Guide |
| Order | Order | Customer orders | π¦ Orders Guide |
| Proforma Invoice | Proforma Invoice | Advance billing | β οΈ In development |
| Sales Invoice | Sales Invoice | Definitive billing | π§Ύ Invoices Guide |
| Receipt | Receipt | Payment voucher | π° Receipts Guide |
| Credit Note | Credit Note | Returns/corrections | β©οΈ Credit Notes Guide |
2. Document Header and Linesβ
Each document is composed of:
- Header: General information (customer, date, totals, etc.)
- Lines (Bodies): Document items (products, quantities, prices, taxes)
3. Customer/Entity Informationβ
Documents can store complete entity information:
- Name/Description
- Tax ID/VAT
- Address, Postal Code, City, State, Country
- Email, Phone
4. Tax Informationβ
Full support for:
- Taxes (VAT) per line
- Second tax rate
- Tax exemption
- Tax region
5. Commercial Informationβ
- Payment mode
- Due date
- Discounts (line and header)
- Commissions
- Document references
6. Logistics Informationβ
For transport documents:
- Loading/unloading location
- Loading/unloading dates
- Carrier
- Warehouses (origin/destination)
7. Document Statusβ
- Open: Document in editing
- Closed: Finalized document
8. Inventory Controlβ
- Stock flow (inbound/outbound)
- Stock behavior
- Origin and destination warehouses
Data Modelsβ
CreateDocumentHeaderCommandβ
Required Fields:
{
"serieId": 1, // Series ID
"documentTypeId": 5, // Document type ID
"entityKeyId": "CLI001", // Customer/supplier ID
"documentBodies": [ // Document lines
{
"itemKeyId": "PROD001", // Product/item ID
"quantity": 2.0, // Quantity
"retailPrice": 50.00, // Unit price
"taxId": 1, // Tax ID
"paymentType": 1, // Payment type
"stockFlow": 1, // Stock flow (1=outbound, -1=inbound)
"stockBehavior": 1, // Stock behavior
"secondTaxId": 0 // Second tax rate
}
]
}
Optional Fields:
{
"entityDescription": "Example Client, Ltd",
"entityVat": "PT123456789",
"entityAddress": "123 Example Street",
"entityPostalCode": "1000-000",
"entityCity": "Lisbon",
"entityState": "Lisbon",
"entityCountry": "Portugal",
"entityEmail": "client@example.pt",
"entityPhone": "210000000",
"obs": "Document observations",
"docReference": "PO-2025-001",
"extraDocReference": "EXTRA-REF",
"dueDate": "2025-12-31",
"paymentModeId": 1,
"paymentTypeId": 1,
"exemptionCode": "M01",
"exemptionReason": "Exempt under article X",
"loadPlaceDescription": "Central Warehouse",
"unloadPlaceDescription": "Customer Store",
"loadPlaceDate": "2025-11-28T10:00:00",
"unloadPlaceDate": "2025-11-28T15:00:00",
"carrierDescription": "XYZ Carrier",
"taxRegionId": 1,
"saleZoneAreaObjectId": 1,
"guid": "550e8400-e29b-41d4-a716-446655440000"
}
UpdateDocumentCommandβ
{
"id": 123, // Required: Document ID
"entityDescription": "New Name", // Optional
"obs": "New observation", // Optional
"docReference": "NEW-REF", // Optional
"extraDocReference": "EXTRA", // Optional
"dueDate": "2025-12-31", // Optional
"paymentModeId": 2, // Optional
"close": true, // Optional: Close document
"documentBodies": [...] // Optional: New lines
}
Usage Examplesβ
Example 1: Create a Simple Invoiceβ
POST /api/v1/invoices
Content-Type: application/json
Authorization: Bearer {token}
{
"serieId": 1,
"documentTypeId": 5,
"entityKeyId": "CLI001",
"entityDescription": "Example Client, Ltd",
"entityVat": "PT123456789",
"obs": "Invoice for order PO-2025-001",
"docReference": "PO-2025-001",
"dueDate": "2025-12-31",
"paymentModeId": 1,
"documentBodies": [
{
"itemKeyId": "PROD001",
"itemDescription": "Product 1",
"quantity": 2.0,
"retailPrice": 50.00,
"taxId": 1,
"paymentType": 1,
"stockFlow": 1,
"stockBehavior": 1,
"secondTaxId": 0
}
]
}
Response (201 Created):
{
"id": 123,
"documentNumber": "FT A/001",
"entityKeyId": "CLI001",
"entityDescription": "Example Client, Ltd",
"total": 190.00,
"totalTaxes": 43.70,
"status": "Open",
"creationDate": "2025-11-28T10:30:00",
"documentBodies": [...]
}
Example 2: Close a Documentβ
PUT /api/v1/invoices/123
Content-Type: application/json
Authorization: Bearer {token}
{
"id": 123,
"close": true
}
Example 3: List Open Documentsβ
GET /api/v1/invoices?status=Open&pageNumber=1&pageSize=20
Authorization: Bearer {token}
Error Handlingβ
The Invoice API uses standard HTTP status codes and returns structured error responses.
Status Codesβ
| Code | Description | When It Occurs |
|---|---|---|
200 OK | Success | Successful operation |
201 Created | Created | Resource created successfully |
400 Bad Request | Invalid request | Validation failed, invalid data |
401 Unauthorized | Unauthorized | Invalid or missing token |
404 Not Found | Not found | Resource doesn't exist |
409 Conflict | Conflict | Concurrency conflict |
500 Internal Server Error | Internal error | Unexpected error |
Error Structureβ
{
"message": "Error description",
"errors": [
"Error detail 1",
"Error detail 2"
]
}
Best Practicesβ
1. Authenticationβ
- β
Always include the JWT token in the
Authorizationheader - β Renew the token before it expires
- β Store the token securely
- β Don't share tokens between users
2. Document Creationβ
- β Validate all data before sending
- β Provide clear descriptions for items and entities
- β Include document references (PO, purchase order, etc.)
- β Correctly set taxes per line
- β Verify stock flow (inbound/outbound)
- β Don't create duplicate documents
3. Document Updatesβ
- β Always get the latest version before updating
- β Update only necessary fields
- β Close documents only when finalized
- β Don't update closed documents (create a credit note)
4. Document Queriesβ
- β Use pagination for large lists
- β Apply filters to reduce data volume
- β Use caching when appropriate
- β Don't load all documents without filters
Next Stepsβ
- π Quotes Guide - Create and manage quotes
- π¦ Orders Guide - Process customer orders
- π§Ύ Invoices Guide - Issue sales invoices
- π° Receipts Guide - Register payments
- β©οΈ Credit Notes Guide - Process returns
Last Updated: December 2, 2025
Document Version: 1.0