تخطَّ إلى المحتوى

Build a Dynamics 365 F&O connector

هذا المحتوى غير متوفر بلغتك بعد.

If your company runs Dynamics 365 Finance and Operations, the connector is an extension in your model: a few tables, a client class, and batch jobs. Most partners already have this skeleton from another integration — a parameters form, an HTTP client with retry rules, staging tables, an execution log. Pointing it at SLFLO changes the mappings and contracts, not the skeleton. This page lists each piece and what it does against SLFLO.

Read the pull connector and master data guides first: they show the same flow with code that runs.

Piece in your extension Against SLFLO
Parameters table and form Base URL https://api.slflo.com/api/integration/v1; the token, stored encrypted; page size (100); your throttle; the last version staged per stream and the last seq per document stream; an on/off switch per flow.
API client class (a .NET HttpClient wrapper called from X++) Stop on 401 and alert (SLFLO never blocks an IP for 401s); wait Retry-After on 429; back off on 500, 502, 503, 504 and timeouts; send an Idempotency-Key on every POST/PUT/DELETE, retries included. See retries.
Throttle Just under rate_limit_per_minute from GET /me (120 by default).
Data contracts Generated or hand-written from openapi-v1.json: OrderDto, OrderLineDto, RefDto, TotalsDto, InvoiceDto, PaymentDto, ReturnDto, for van loads LoadPushDto, LoadResultDto, LoadDto, and for unloads UnloadPushDto, UnloadDto. Ignore fields you don’t know — new ones may be added to v1.
Staging tables Header and lines, with a unique index on (SLFLO id, version, line number) and a status field.
Batch jobs (SysOperation) One per flow — orders, invoices, payments, returns, master data — on a recurrence, each writing to your execution log with SLFLO’s request_id for every failed call.
  1. Pull GET /orders?filter[status]=ERP_PENDING&filter[version_after]=<last staged version>&per_page=100, following meta.next_version_after until has_more is false. Customer, branch, rep, product and unit come inline with both keys — no second call to look them up.
  2. Stage every line under the unique index. A duplicate insert is not an error; skip it.
  3. Create one sales order per SLFLO order. Put the SLFLO order id in the sales order’s customer reference (CustomersOrderReference on the sales order header entity) or in a field of your own, and search for it before creating. A job that died after creating finds its own sales order.
    • Customer account: customer.external_ref. Delivery address: branch.external_ref, which reads ACCOUNT/BRANCH. A shop the rep added on the phone has customer.external_ref: null until you adopt it (see adopting a record); adopting it does not raise the order’s version, so match a waiting order by customer.id too, or read it again with GET /orders/{id}.
    • Rep: sales_rep.code is the rep’s SLFLO code (EMP-017), set once and never changed — map it to your worker or sales group. sales_rep.external_ref is empty in v1 (no rep push).
    • Warehouse: an order waiting for you has "warehouse": null, because nothing has left a SLFLO van or warehouse yet. Take the warehouse from your own rule — the rep’s default warehouse, for example. See Which warehouse.
    • Lines: product.external_ref is your item number, unit.external_ref your unit symbol, quantity, unit_price, discount; is_free_goods lines at zero price.
    • Prices and VAT: the rep quoted the customer unit_price and the VAT in tax[]. Fix the line price to it rather than letting trade agreements re-price, and map the tax code (VAT) to your sales tax groups.
  4. Ack POST /orders/{id}/ack, ACCEPTED with the sales order number as external_ref, or REJECTED with a reason_code and the infolog text as message (the office reads it). Many at once: POST /acks with "entity": "order".

A refused order the office fixes comes back at a higher version through the same pull; see the refusal path. An order you accepted never changes or gets cancelled in SLFLO afterwards; see what happens to an order after your answer.

  • Read GET /payments?filter[seq_after]=<last receipt seq> — each receipt once, in issue order — or by version.
  • One journal line per payment: account type Customer, account customer.external_ref, credit amount, date collection_date. Map method (CASH, CHEQUE, TRANSFER, INSTAPAY, WALLET, from GET /reference/payment-methods) to your methods of payment; a cheque carries bank, number and due date for post-dated cheques.
  • Settle against the debts in allocations. kind is INVOICE — invoice names it with both keys, its external_ref being what you acked the invoice with (empty until you have) — or OPENING_BALANCE, a balance the customer carried in from before SLFLO (invoice is null). A payment never allocates to a credit note; what it didn’t clear is on_account.
  • Ack with a key unique to the payment, such as <journal>-<line>; the journal number or voucher, which several payments share, goes in external_number. See acks.
  • A payment reversed or a cheque bounced later is pending again (filter[ack]=pending) with a reversal (a cheque BOUNCED or VOIDED always has one): reverse the journal and ack again. reversal.reversed_at is when the office recorded it in SLFLO. A cheque that only moves on — handed over, deposited, cleared — also makes the payment pending again; nothing changes in money, so ack it with the same keys. See invoices by seq.
  • A payment reversed before you booked it is still pending, now REVERSED, until you answer it: answer REJECTED with reason_code REVERSED_IN_SLFLO, and the office reads that it was reversed in SLFLO and needs nothing more. SLFLO’s balance already leaves it out, whatever you answer.
  • Read GET /returns?filter[seq_after]=<last credit note seq>; a return gets its seq when it is credited (credit_note_number).
  • Each line points at the original invoice line (invoice with both keys, invoice_line_number); map reason (from GET /reference/return-reasons) to your return reason codes, and create a return order (RMA) or a credit note as your process books returns.
  • A line of a lot-tracked product names its lot in lot (the code, as on the invoice line’s lots): put it in the return line’s InventBatchId. batch_id is SLFLO’s own id for it.
  • Each line says where its goods went in held_back: false — back on the van for sale; true — into the van’s held-back place (VAN-03-Q), never sellable. Every expired line is held back, and so is a line the rep held back on a Did not sell or Wrong delivery return; a damaged line the inspector put back on the shelf is not. Arrive the goods where the line says, whatever the return’s reason.
  • Amounts: line_total is what the line credits — its share of what the invoice line was billed, after discount, VAT included — and total is their sum. unit_price is the invoice line’s price before discount. A credit-note line posted with a sales tax group takes line_total less its VAT, or the VAT is credited twice.
  • location is where the goods came back to: its code is the SLFLO van or warehouse code, as for an invoice’s warehouse.
  • SLFLO applies a credit note to the invoice it credits first, then to the oldest debt; that application is not in v1, so settle your credit note against invoice the same way.
  • A credited return never changes. Ack it with your credit note’s id. SLFLO keeps it as the return’s external_ref (what filter[external_ref] and lookups find) and does not print it on its own credit note.

SLFLO issues an invoice for what it delivers: every van sale, at the shop, and any order the office delivers in SLFLO. If you don’t invoice those sales in Dynamics yourself, read GET /invoices?filter[seq_after]=… and book them — as your accountant decides, for example as free text invoices — then ack with your voucher. The counter has no gaps, so you can prove you hold every invoice.

  • One invoice per delivery. An order delivered in two parts has two invoices, each with only the lines that moved. A line’s line_number is the number of the order line it delivers, so match lines on it.
  • Line amounts. discount is the whole line’s discount (this delivery’s share of the order line’s). line_total is what the line is billed with VAT: quantity × unit_price − discount, plus the VAT in tax[] unless prices_include_tax. The net amount is line_total less the line’s tax. A free-goods line has unit_price 0, VAT 0 and line_total 0.
  • An invoice never changes, so your first ACCEPTED answer is final. If you refused one and later book it (the shop linked, the period opened), ack it ACCEPTED: SLFLO takes it.

Every invoice says where its goods left from in warehouse: the rep’s van for a van sale (VAN-03), the warehouse for a delivery the office recorded (MAIN). One invoice always leaves from one place, so the lines carry no warehouse of their own. Post the invoice’s inventory against that place:

  • Map warehouse.code to your InventLocationId — through a SLFLO reference field on your warehouse (for example SlfloWarehouseRef), or the same code when you name them alike. warehouse.external_ref is your key when SLFLO knows it for that warehouse; vans have none.
  • warehouse is null only when no stock moved in SLFLO — a company that keeps all its stock in Dynamics. Then fall back to the rep’s default warehouse, as you would without SLFLO.

Orders carry the same field once goods have left: a van sale’s order names its van, and an order the office delivered names the warehouse of its first delivery (an order delivered in parts from two places still names the first; each invoice names its own).

For a product SLFLO tracks by lot, each invoice line lists the lots its goods came from in lots, earliest expiry first — the van’s lots for a van sale, the warehouse’s for a delivery:

"lots": [
{ "lot": "B-0925", "expires_on": "2026-10-20", "quantity": "4.000", "base_quantity": "4.000" },
{ "lot": "B-1101", "expires_on": "2026-11-15", "quantity": "6.000", "base_quantity": "6.000" }
]
  • lot is the lot code: your InventBatchId, the same code your load and unload journals send.
  • quantity is in the line’s unit, three places; when the whole line came from lots, the lots add up to the line’s quantity. base_quantity is the same amount in the product’s base unit — your inventory unit when you pushed it as the base unit.
  • One line can come from two lots, when the first ran out. Keep the sales line as billed and give its inventory the lots: register each lot’s quantity against its batch when you pick or post the line, or split the line into one line per lot with the lot’s quantity if your process wants one batch per line.
  • A product SLFLO doesn’t track by lot has "lots": [], and so does every line when no stock moved in SLFLO (warehouse is null). Then let Dynamics pick the batch as it would without SLFLO.
  • Two lines of one product (the paid line and its free goods) share the lots in line order.

Check which products SLFLO tracks by lot with GET /lookup?entity=product&external_ref=<ItemId>: product.tracking is BATCH, NONE or SERIAL. Compare it with your item’s tracking dimension group before the first load, so both sides agree on which lines carry a batch.

When the company’s stock is managed in Dynamics (Stock is managed in your ERP, GET /me → company.stock_managed_by_erp), every van load is a transfer journal from a warehouse to the van’s warehouse. Stock from your ERP has the calls; in the extension:

Dynamics 365 Against SLFLO
Transfer journal saved, Send to SLFLO PUT /stock/loads/{JournalId} with van and from as SLFLO location codes (the warehouse’s SLFLO reference, else its InventLocationId), the journal number as number, each line’s item, unit, quantity and batch. Store the answer’s id and LD- number on your queue row.
Journal edited while the load waits The same PUT with a new Idempotency-Key: replaced (a new load id) or updated
Journal deleted DELETE /stock/loads/{JournalId}
Answers GET /stock/loads?filter[version_after]=… each run. Act on a row only when its id is the journal’s current SLFLO load id. ACCEPTED → post the journal; REFUSED → show refusal.reason and refusal.note on the journal and alert the storekeeper.
Refused journal fixed The same PUT again with a new key: a re-send, a new load id
409 LOAD_ALREADY_CHECKED on an edit or delete The rep already accepted: don’t post the edited journal; mark it failed and alert
Waiting too long GET /stock/loads/{JournalId} re-checks it
New van GET /lookup?entity=van&external_ref=<code> before the first load: exists, and van.rep to compare with your rep mapping

Post the journal only on ACCEPTED. SLFLO already put the goods on its van when the load arrived and took them back if the rep refused, so there is nothing to tell SLFLO after posting.

The storekeeper counts the van in Dynamics and posts a transfer journal back to the warehouse, and the held-back goods in their own journal from the van’s quarantine warehouse (VAN-03-Q) to the warehouse’s (WH-MAIN-Q). Stock from your ERP has the call; in the extension:

Dynamics 365 Against SLFLO
Unload journal posted PUT /stock/unloads/{JournalId} once, with van, to (SLFLO location codes), held_back: true for the quarantine journal, counted_at = the posting time, the journal number as number, and each counted line’s item, unit, quantity and batch. Store the answer’s id and UL- number.
409 LOAD_STILL_WAITING or VAN_DAY_NOT_ENDED (retryable: true) Keep the journal queued and send it again on a later run, with the same body. A load still waits on the van, or the rep hasn’t ended the day.
409 UNLOAD_ALREADY_RECORDED The journal was edited after SLFLO recorded it: mark the queue row failed and alert; a correction is a new journal.
shortages in the answer The rep’s shortage, written off SLFLO’s van. It stays on the Dynamics van until your accountant clears it, so Dynamics van = SLFLO van + its uncleared shortages.
Re-check GET /stock/unloads/{JournalId}

Send only posted journals: a posted journal isn’t deleted, and SLFLO records each ref once.

SLFLO From Dynamics 365 Call
Customer Customer account (AccountNum), name, credit limit, blocked, customer price group PUT /customers/{AccountNum}
Branch The customer’s delivery addresses PUT /customers/{AccountNum}/branches/{ref}
Unit Unit symbol PUT /units/{Symbol} or POST /batch/units
Product Item number, name, inventory unit, active PUT /products/{ItemId} or POST /batch/products
Sellable units Unit conversions to the inventory unit PUT /products/{ItemId}/units
Price list Customer price group PUT /price-lists/{PriceGroup}
Prices Sales trade agreements for the group, resolved to one price per item, unit and from-date PUT /price-lists/{PriceGroup}/prices (≤ 500 rows, several merge calls when more)
Balance The customer’s open balance, and when it was taken PUT /customers/{AccountNum}/balance or POST /batch/balances

There is no id to store: you push by your own keys. Keep a hash of each payload you sent (MD5 or SHA-256 of the JSON) in a small table and skip the call when it hasn’t changed; SLFLO answers unchanged anyway, but skipping saves the request. Send the record’s modified time as source_version so two jobs racing can’t roll a record back.

Fetch SLFLO’s code lists once and map them in small tables of your own: GET /reference/payment-methods, return-reasons, units, warehouses, tax-codes. Each item has code, a name in English and Arabic, and — for the company’s own lists — your key beside ours.

  1. Parameters: the base URL and a sandbox token (sfi_live_…); check it with GET /me.
  2. Map the code lists.
  3. Master data out: units, price groups, items, prices, customers, balances — by your keys, with the payload-hash skip.
  4. Documents in: orders, then payments, returns and invoices — pull, stage, create with find-before-create, ack.
  5. When the company’s stock is kept in Dynamics: load journals out and their answers back, then posted unload journals (stock from your ERP, its worked example Karim’s day). In the batch, read the load answers before you post the day’s invoices, and send unloads after them.
  6. Run the go-live checklist against the sandbox (the stock sandbox for step 9), then switch the parameters to a live token.