Dolibarr创建销售订单记录的默认API及字段要求咨询
Absolutely, Dolibarr does come with a default API for creating sales order records—here's everything you need to know to get it working properly:
1. Default Sales Order API Availability
Dolibarr's built-in RESTful API module (you'll need to enable it first via the admin panel) fully supports CRUD operations for sales orders, including a dedicated POST endpoint for creating new records. The API Explorer you mentioned is the perfect starting point to browse all available endpoints and their capabilities.
2. Required/Useful Fields for POST Requests
The sample { "request_data": [ "string" ] } you see is just a generic placeholder—you'll need to pass a structured JSON object with actual order details instead. Here are the core fields you'll typically need:
fk_soc: Customer ID (required, must match an existing customer in your Dolibarr instance)date: Order date (format like"2024-05-20", required)lines: Array of order line items (each item is an object with these keys):desc: Product/service description (required if not linking to a system product)qty: Quantity of the item (required)price: Unit price (required)fk_product(optional): ID of an existing product in Dolibarr (if using catalog items)
payment_condition: Payment terms (e.g.,"30 days"or the ID of a pre-defined condition in your system)fk_user_author(optional): ID of the user creating the order; if omitted, the API-authenticated user will be used
Here's a practical example of a valid request body:
{ "request_data": [ { "fk_soc": 123, "date": "2024-05-20", "payment_condition": "15 days", "lines": [ { "desc": "Custom Gaming PC", "qty": 1, "price": 1499.99 }, { "fk_product": 456, "qty": 2, "price": 49.99 } ] } ] }
3. Where to Find Full Field Requirements
You don't need to guess—there are three reliable ways to get the complete field list and validation rules:
- Built-in API Explorer: After enabling the RESTful API module, navigate to
your-dolibarr-domain/api/index.php/explorer. Locate thesalesordersPOST endpoint (usually at/api/index.php/salesorders), and you'll see a detailed breakdown of every available field, whether it's required, its data type, and even example values. You can also test requests directly here. - Dolibarr Data Dictionary: In the admin panel, go to Settings > Data Dictionary (the exact menu name might vary slightly by version). Search for
commande(the database table name for sales orders) to view all table fields—most API field names map directly to these database columns. - Source Code Reference: For deep dives, check the
htdocs/core/modules/api/modCommandeApi.class.phpfile in your Dolibarr installation. This file defines the API's field mappings and validation logic.
内容的提问来源于stack exchange,提问作者piranhas

