Economic Connector - SendOrderToBackoffice
This function synchronizes App4Sales orders to the Economic ERP system via its REST API. It handles the creation of both order headers and individual order lines, including pricing, discounts, and customer information. The process involves retrieving product information from Economic, mapping App4Sales data to Economic's order structure, and then creating the order, optionally marking it as sent.
1. Data Source Configuration
The connector communicates with the Economic REST API at https://restapi.e-conomic.com/. Authentication is performed using the following HTTP headers:
X-AppSecretToken: Provided by the Economic application secret.X-AgreementGrantToken: Provided by the connector settings (Agreement Grant Token).Content-Type: Set toapplication/json.
Data is pushed from App4Sales to Economic.
2. Data Mapping Table
Order Header Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Customer Number |
| Parsed from |
VAT Zone |
| Derived from the App4Sales customer's dynamic field named "VatZone" ( |
Payment Terms |
| Derived from the App4Sales customer's dynamic field named "PaymentTerms" ( |
Sales Document Layout |
| Derived from the App4Sales customer's dynamic field named "Layout" ( |
Currency |
| Retrieved from |
Order Date |
| Set to the current date and time ( |
Delivery Date |
| Mapped from |
Notes (Heading) |
| Mapped from |
Notes (Text Line 1) |
| Mapped from |
Notes (Text Line 2) |
| Mapped from |
Your Reference |
| Mapped from |
Sales Person |
| Derived from |
Recipient Name |
| Mapped from |
Recipient VAT Zone |
| Mapped from the customer's VAT zone. |
Delivery Location Number |
| If |
Delivery Address |
| If an alternate address is provided and valid, it's used. Otherwise, the customer's delivery/visit address is used. |
Delivery City |
| Same logic as Delivery Address. |
Delivery Country |
| Same logic as Delivery Address. |
Delivery Zip |
| Same logic as Delivery Address. |
Order Line Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Product |
| The Economic Product entity retrieved based on |
Description |
| Mapped from |
Quantity |
| Mapped from |
Discount Percentage |
| Mapped from |
Unit Net Price |
| Calculated as |
Unit Number |
| Retrieved from the item's |
Unit Cost Price |
| Retrieved from the item's |
3. Special Logic & Filters
SOAP vs. REST API: The connector can be configured to use either a SOAP-based or REST-based API for sending orders. The choice is determined by the
UseSoapSendOrderProcesssetting. This document describes the REST API process.Missing Properties Fallback: If critical order header properties (Layout, Payment Terms, VAT Zone, Currency) are missing after initial mapping from customer dynamic fields, the connector attempts to retrieve them from the customer, customer group, or a fallback layout name setting in Economic.
Product Validation: Before creating order lines, the connector verifies that all items in the App4Sales order exist as products in Economic. If any products are missing, a
MissingProductsExceptionis thrown, preventing the order from being sent.Optional Order Sending: Orders are initially created as drafts in Economic. Based on the
MarkNewlyCreatedOrdersAsSentsetting, the drafted order can be automatically marked as "sent" in Economic immediately after creation.Batching Product Retrieval: Product information from Economic is retrieved in batches of 200 items to optimize API calls.
4. Domain Specifics
Order Header Logic
Customer selection is based on the order.Customer object passed to the function. The order date is always the current date. Delivery date is mapped from the App4Sales order date unless configured otherwise. References, notes, and sales person assignments are mapped as detailed in the Order Header Mapping table. The recipient name and VAT zone are derived from the App4Sales customer. Delivery address information is prioritized from an alternate address, then from the customer's delivery/visit address. If AddressLine3 contains a valid integer, it's interpreted as an existing Economic delivery location ID.
Line & Pricing Logic
Each order line in App4Sales is converted to an Economic order line. The unit net price for each line is calculated considering any discounts. Unit number and unit cost price are extracted from the Item.ExtraData JSON field within App4Sales. Products are looked up in Economic based on their item codes.
Charges & Attachments
This specific SendOrderToBackoffice method (REST API) does not explicitly handle charge lines (freight, payment fees) or attachments (PDF, JSON exports, images). If these are required, they would need to be managed by other processes or settings not covered in this function.
Responses & Error Handling
Upon successful order creation, the Economic order number is returned and used to update the App4Sales order via OrdersContext.Instance.UpdateOrderNumber. If products referenced in the App4Sales order are not found in Economic, a MissingProductsException is thrown. Errors during API calls (e.g., network issues, invalid data) are handled by the underlying IRestService and may result in exceptions.
5. Related Settings & Prerequisites
UseSoapSendOrderProcess: (Boolean) If set to
true, the connector will use the SOAP API for sending orders instead of the REST API.AgreementGrantToken: (String) Required for authenticating with the Economic API.
MarkNewlyCreatedOrdersAsSent: (Boolean) If set to
true, orders created as drafts in Economic will immediately be marked as "sent".DontSendDeliveryDate: (Boolean) If set to
true, the delivery date will not be sent to Economic.FallbackSalesDocumentLayoutName: (String) If a layout is not found from the customer or customer group, this setting specifies a fallback layout name to search for in Economic.
6. Known Limitations
An alternative SOAP-based implementation (SendOrderToBackofficeSoap) exists, enabled by the UseSoapSendOrderProcess setting. While functionally similar in its goal of sending order data, it uses a different technical approach for API communication and may have subtle differences in data handling (e.g., VAT zone defaulting, exchange rate setting) compared to the detailed REST API documentation provided here.