C6_PEDCLI) and looks up in Protheus before sending anything. When it cannot be sure (the id is used by another order, Protheus does not answer, the field was not filled), it does not send the order and the run fails with the reason, so you can check it. See Limits for what this check cannot cover.
It uses the same Protheus REST service and the same kind of access as the TOTVS Protheus source.
Before you start: set up Protheus
Protheus receives the orders through its integration layer, the EAI (standard messageORDER, routine MATA410). Ask your Protheus administrator to set up the items below. They are done once.
- REST service published over HTTPS. Nekt reaches your Protheus over the internet, so the REST service must be published with a valid certificate (for example
https://erp.mycompany.com.br:8400/rest), with security on (SECURITY=1) and covering the company group that receives the orders. On TOTVS Cloud, use the REST address of your environment. - EAI route (Configurador > Ambiente > Schedule > Cadastro de Rotas EAI): create a route whose product and application are NEKT (or the name you set in EAI source application), channel REST. The REST address of the route can stay empty: Protheus never calls Nekt.
- EAI adapter (Configurador > Ambiente > Schedule > Adapter EAI): routine MATA410, message ORDER, version 4.003, format JSON, Recebe = Sim, Envia = Não, method Síncrono (required: the connector stops if the adapter is asynchronous), route = the route above. If the ORDER adapter of purchase orders (MATA120) is also set up, both must use the same format.
- Company de/para (Configurador > Ambiente > Schedule > Emp.Fil Msg. Única): reference NEKT (the same name as the route), with the company and branch codes you type in the connection mapped to the same company group and branch in Protheus.
- A user for the integration, with access to the company and branch of the orders, permission to include sales orders (Faturamento, MATA410), and read access to the customer (SA1), product (SB1), payment term (SE4), TES (SF4), seller (SA3), price table (DA0) and sales order item (SC6) tables.
- Up-to-date Faturamento routines. The connector writes its order id in the item field Pedido Cliente (
C6_PEDCLI) and reads it back to avoid duplicates. Recent builds of the ORDER adapter fill this field; if yours does not, the connector stops after the first order and asks for the update.
An asynchronous ORDER adapter is not supported yet. If Protheus answers that it queued an order for later processing, the run stops. Pause the destination’s schedule right away and set the adapter to Síncrono before the next run: while the adapter stays asynchronous, every run queues the same order again. Then check that order in the EAI monitor of Protheus, because the queue may still create it.
1. Add your TOTVS Protheus access
- In the Destinations tab, click on the “Add destination” button located on the top right of your screen. Then, select the TOTVS Protheus option from the list of connectors.
-
Click Next and you’ll be prompted to add your access:
- Protheus REST URL: the address of the Protheus REST service as reached from the internet, including the port and the REST path, for example
https://mycompany.protheus.cloudtotvs.com.br:4050/rest. It must usehttps. - Username and Password: the Protheus user created for this integration.
- Company code and Branch code: the company group (grupo de empresas) and branch (filial) where the orders are created, exactly as in Protheus (for example
01and0101). - Dry run (test mode): on by default. The connector checks every order and shows the first orders it would send and a summary in the run log, and creates nothing.
- Max records per run: the maximum number of orders created per run; the others wait for the next runs. Leave it empty for no limit. Use 1 on the first real run.
- EAI source application: the name of this integration in the Protheus EAI. Keep NEKT unless your administrator used another name in the route and company de/para.
- Default TES: optional. The TES (3 characters, an outgoing TES) used for items that bring no TES of their own. Without it, Protheus applies its own rules (the product’s default TES or the TES Inteligente).
- Enable partial success: when off, the run is marked as failed if any order was refused (the other orders are still created). When on, refused orders are only listed in the run log.
- Verify SSL certificate (advanced): keep it on unless your server uses a self-signed certificate.
- Protheus REST URL: the address of the Protheus REST service as reached from the internet, including the port and the REST path, for example
- Click Next.
2. Select your data to send
-
Select the layer and then the table with your orders. Build it with a Query in the shape described below.
Tip: The table can be found more easily by typing its name.
- Click Next.
Input table: one row per order item
The table has one row per item. The order columns (customer, payment term, date…) repeat on every item row of the same order, and the connector groups the rows byorder_id. Column names must be exactly the ones below (upper or lower case); other columns are ignored.
Example input table:
This table creates two orders:
PV000123 with two items and PV000124 with one.
Item discounts are not supported yet: send the net price in
unit_price. An item_discount column is accepted when empty or 0; any other value refuses the order. Discounts will come in a later version, once confirmed on a real Protheus.3. Configure your TOTVS Protheus data destination
- Describe your destination for easy identification within your organization. You can inform things like what data it sends, to which team it belongs, etc.
- To define your Trigger, consider how often new orders must reach Protheus. Orders already created are skipped on every run, so the table can keep old orders.
- Click Done.
How each run works
- The connector connects to Protheus and reads the orders of the table.
- It checks every order: required columns filled, quantities and prices greater than zero, the same customer and payment term on every row of the order.
- It looks each
order_idup in the Pedido Cliente field of Protheus. An order found for the same customer and created through the EAI is counted as already exists, listed in the run log with its Protheus number, and skipped. If the id is in the Pedido Cliente of another order (another customer, or an order typed by hand), the order is refused with that reason. - It checks in Protheus, with read-only queries, that the customer and store, products, payment term, TES, seller and price table exist and are not blocked.
- It checks that Protheus has no order created through the EAI, without an id in Pedido Cliente, with the same customer and the same products as an order of your table (in the last 30 days, or on the
order_dateof your orders). Such an order may be one created before without its id, or an order of another integration that also writes through the EAI. While one exists, the run creates no order at all and lists each Protheus order found. To release it:- if the Protheus order found is one of your table’s orders, fill its Pedido Cliente with that
order_id: the next run counts it as already existing; - if it belongs to another integration, fill its Pedido Cliente with any value (or adjust that order).
- if the Protheus order found is one of your table’s orders, fill its Pedido Cliente with that
- Dry run: it shows the first orders it would send and the summary N would be created / M already exist / K would be refused, and stops there.
- Real run: it sends the remaining orders one by one, each only once, up to Max records per run, and confirms each one in Protheus (including that Protheus kept its issue date and marked it as created through the EAI; if not, the run stops at once and asks you to pause the pipeline and contact support). The run log lists the orders created with their Protheus number, and the orders refused with the reason Protheus gave. If Protheus does not answer for an order and the order does not show up afterwards, the connector sends nothing else and the run fails; the next run looks that order up before sending it.
If the first orders sent are all refused with the same message, the connector stops sending: this usually means the EAI setup in Protheus is incomplete (adapter, route or company de/para). The message from Protheus is shown in the run log.
Limits
- The duplicate check relies on the Pedido Cliente field: an order whose field was cleared or changed in Protheus can be sent again.
- An order deleted in Protheus is no longer found: if its row is still in your table, it is sent again. Remove such rows from the table.
- There is no lock between runs: do not schedule the destination more often than a run takes, so that two runs never send the same orders at the same time.
- Item discounts are not supported yet.
- Do not use it together with another EAI ORDER integration that leaves the Pedido Cliente field (
C6_PEDCLI) empty for the same customers and products: its orders block Nekt’s writes until the field is filled. - Never reuse an
order_idfor a new order: an id already in Protheus for the same customer is treated as an existing order, even if the items differ. - The check for orders created without their id (step 5) only matters if your Protheus does not fill the Pedido Cliente field. It does not catch such an order if its products were changed afterwards in your table, or if it is older than 30 days and its issue date differs from the current
order_date. Keeporder_dateas the order’s fixed date.
Check your new destination!
- Once completed, you’ll receive confirmation that your new destination is set up!
- You can view your new destination on the Destinations page. Run it with Dry run on and check the run log. Then turn Dry run off, set Max records per run to 1, run it again and check the new order in Protheus before raising the limit.
If you encounter any issues, reach out to us via Slack, and we’ll gladly assist you!