m34dev/swiftdolibarr
A Swift package providing `Codable` and `Observable` model types for the [Dolibarr ERP CRM](https://www.dolibarr.org) REST API. Decode JSON responses from the Dolibarr API directly into strongly-typed Swift objects and encode them back for create/update requests.
Requirements
- Swift 6.1+
- iOS 18+ / macOS 15+ / Mac Catalyst 18+ / tvOS 18+ / visionOS 2+ / watchOS 11+
- Dolibarr v18+ (may work with older versions of Dolibarr)
Installation
Add SwiftDolibarr as a dependency in your Package.swift:
dependencies: [
.package(url: "https://lab.frogg.it/dolibarr/swiftdolibarr.git", from: "1.0.0"),
]Then add it to your target's dependencies:
.target(
name: "YourTarget",
dependencies: ["SwiftDolibarr"]
),Supported Dolibarr Objects
Core
| Module | Models | |---|---| | Third Parties | DolibarrThirdParty, DolibarrContact | | Products & Stock | DolibarrProduct, DolibarrWarehouse, DolibarrStockMovement | | Quotes | DolibarrQuote, DolibarrQuoteLine | | Orders | DolibarrOrder, DolibarrOrderLine | | Invoices | DolibarrInvoice, DolibarrInvoiceLine | | Interventions | DolibarrIntervention, DolibarrInterventionLine | | Expense Reports | DolibarrExpenseReport, DolibarrExpenseReportLine | | Projects & Tasks | DolibarrProject, DolibarrTask | | Agenda Events | DolibarrAgendaEvent | | Users | DolibarrUser, DolibarrUserPermissions | | Setup | DolibarrCountry, DolibarrExpenseReportType, DolibarrShippingMethod, DolibarrPaymentTerm |
External
| Publisher | Modules | Models | |---|---|---| | CODE42 | LaReponse | LaReponseArticle, LaReponseComment |
Usage
Decoding API responses
import SwiftDolibarr
let data: Data = // ... JSON from Dolibarr REST API
let decoder = JSONDecoder()
// Decode a single invoice
let invoice = try decoder.decode(DolibarrInvoice.self, from: data)
print(invoice.ref) // e.g. "FA2026-0001"
print(invoice.totalInclTax) // e.g. "1200.00"
// Decode a list of third parties
let thirdParties = try decoder.decode([DolibarrThirdParty].self, from: data)Creating objects for API requests
let newInvoice = DolibarrInvoice(
date: Int(Date().timeIntervalSince1970),
typeCode: "0",
paidCode: "0",
lines: [],
thirdPartyId: "42",
statusCode: "0"
)
let encoder = JSONEncoder()
let jsonData = try encoder.encode(newInvoice)
// Send jsonData to the Dolibarr APIObject statuses
Each object type has predefined statuses mapped from Dolibarr statuses:
let invoice: DolibarrInvoice = // ...
let status = invoice.statusArchitecture
All models conform to Codable, Hashable, Identifiable, and are marked @Observable for seamless SwiftUI integration. The type hierarchy is:
DolibarrObject— Base protocol enforcingidpropertyCommonBusinessObject— Base class adding status, entity, notes, and extra fieldsCommonCommercialTransactionObject— Transactional class adding ref, totals, linked third party, and currency for documents (invoices, orders, quotes)DolibarrThirdPartyDolibarrProductDolibarrQuote...- Final object classes
Property names are mapped to Dolibarr API field names via CodingKeys, so you work with idiomatic Swift naming while the JSON stays compatible with the Dolibarr API.
Contributing
Contributions are welcome! This project is maintained by M34D. Please see CONTRIBUTING.md for guidelines on reporting bugs, suggesting features, submitting changes, and adding new models.
Versioning
This project uses Semantic Versioning with the following scheme: MAJOR.MINOR.PATCH
License
Swift Dolibarr is licensed under the Apache License 2.0. See LICENSE for details.
Package Metadata
Repository: m34dev/swiftdolibarr
Default branch: main
README: README.md