Querying Documents
The API offers two approaches for retrieving documents:
- Type-specific queries like
invoice/invoices: return a concrete type with all its fields directly available - Generic queries like
document/documents: return theDocumentReadinterface, useful when working across document types
Type-specific queries
Use these when you know the document type upfront. They return the full type (e.g. InvoiceRead) with all fields directly accessible, with no inline fragments needed.
Getting a single invoice
query {
invoice(companyId: 1, documentId: 1234) {
data {
documentId
number
date
expirationDate
totalValue
grossValue
taxesValue
status
customer {
customerId
name
vat
}
products {
productId
name
qty
price
discount
}
}
}
}
Listing invoices
query {
invoices(companyId: 1, options: {
pagination: { page: 1, qty: 20 }
order: { field: date, sort: DESC }
}) {
data {
documentId
number
date
totalValue
status
entityName
}
options {
pagination {
page
qty
count
}
}
}
}
The same pattern applies to all document types; replace invoice/invoices with the relevant query name.
Available type-specific queries
| Document type | Single | List |
|---|---|---|
| Invoice | invoice | invoices |
| Receipt | receipt | receipts |
| Credit Note | creditNote | creditNotes |
| Debit Note | debitNote | debitNotes |
| Estimate | estimate | estimates |
| Simplified Invoice | simplifiedInvoice | simplifiedInvoices |
| Pro Forma Invoice | proFormaInvoice | proFormaInvoices |
| Invoice Receipt | invoiceReceipt | invoiceReceipts |
| Delivery Note | deliveryNote | deliveryNotes |
| Purchase Order | purchaseOrder | purchaseOrders |
See the queries reference for the complete list, including supplier and migrated document types.
Generic queries
The generic document and documents queries work across all document types. They return the DocumentRead interface, which includes fields common to every document.
Getting any document by ID
query {
document(companyId: 1, documentId: 1234) {
data {
documentId
documentTypeId
number
date
totalValue
status
entityName
entityVat
}
}
}
This works regardless of whether the document is an invoice, receipt, credit note, or any other type.
Listing all documents
query {
documents(companyId: 1, options: {
pagination: { page: 1, qty: 20 }
order: { field: date, sort: DESC }
}) {
data {
documentId
documentTypeId
number
date
totalValue
status
entityName
}
options {
pagination {
page
qty
count
}
}
}
}
Common fields on all documents
The DocumentRead interface provides these fields on every document type:
| Field | Description |
|---|---|
documentId | Unique document identifier |
documentTypeId | Type of document (invoice, receipt, etc.) |
number | Sequential number within the document set |
date | Document date |
totalValue | Total document value |
status | 0 = draft, 1 = finalized |
entityName | Customer/supplier name |
entityVat | Customer/supplier VAT number |
documentSetId | ID of the document set used |
documentSetName | Name of the document set |
yourReference | Customer's reference |
ourReference | Internal reference |
deletable | Whether the document can be deleted |
pdfExport | URL to download the PDF |
See DocumentRead for the full list.
Using inline fragments for type-specific fields
When using generic queries, some fields are only available on specific document types. Access them with inline fragments:
query {
document(companyId: 1, documentId: 1234) {
data {
# Common fields - available on all documents
documentId
number
date
totalValue
entityName
# Invoice-specific fields
... on InvoiceRead {
expirationDate
grossValue
taxesValue
globalDiscount
products {
productId
name
qty
price
}
customer {
customerId
name
}
}
# Receipt-specific fields
... on ReceiptRead {
payments {
paymentMethodId
value
}
relatedWith {
relatedDocumentId
value
}
}
}
}
}
The API returns only the fragment matching the actual document type. If the document is an invoice, you get the InvoiceRead fields; if it's a receipt, you get the ReceiptRead fields. Fragments for other types are silently ignored.
Next steps
- Pagination: Page through large document lists
- Filtering, Search & Ordering: Filter by date, status, type and more
- Deletion: Remove draft documents or understand finalized document rules
- See the queries reference for all available document queries