# eBay → SAP S/4HANA sales order (n8n manual starter)

## Scenario and scope

A seller fulfils a paid eBay marketplace order from their SAP-managed business. Import a selected eBay order as an S/4HANA sales order via the OData V2 Sales Order (A2X) service, `API_SALES_ORDER_SRV`. This is a manual starter, not a scheduled or production-ready sync. It does not create a purchase order, delivery, invoice or payment posting.

No live eBay/SAP tenant was available for testing. Validate the import, API availability and actual document creation in your own non-production systems. API availability and permitted authentication vary by SAP edition and release.

## Prerequisites

- An n8n version supporting HTTP Request node v4.2 and Code node v2. Import through n8n's “Import from File” command.
- eBay seller access to the selected order. Configure an n8n OAuth2 API credential for eBay's authorization-code/user-token flow, including `https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly`, using your registered application's callback URL. Assign it to **Get eBay order**. Do not use an application-only token. The template targets eBay production; for a sandbox test, also change the request host to `api.sandbox.ebay.com` and use matching sandbox credentials/orders.
- A non-production S/4HANA system exposing the Sales Order (A2X) OData V2 service and authorising read and create operations. Configure its communication arrangement/service user as required by your edition. This template uses Basic Auth over HTTPS; if your tenant requires OAuth2 or another supported method, change both SAP nodes accordingly.
- Assign the **same SAP credential** to **Fetch SAP CSRF token** and **Create SAP sales order**. The workflow transfers the returned token and session cookies to the POST request. Never paste passwords or tokens into the configuration node.
- Existing SAP business partner/customer, valid sales area, sales document type, and saleable materials with maintained sales units. Partner determination and pricing must work for that customer. No business partners or materials are created.

## Configure and run

1. Download both the workflow JSON and this guide. Import the JSON into n8n. It is inactive and has only a manual trigger.
2. Edit **Configure connection**. Replace every `YOUR_…` placeholder. `sapBaseUrl` must be an HTTPS origin only (no path, credentials or query). Set one `ebayOrderId`, the correct SAP sold-to customer, sales area and document type. `OR` is illustrative; confirm your tenant's configuration. Map every eBay SKU to a SAP material in `materialBySku`. Ensure the SAP sales unit corresponds to the marketplace quantity unit.
3. Verify the selected eBay order is paid, fulfilment has not started, and no cancellation has been requested. The mapping node rejects other statuses, missing mappings and invalid quantities. This does not cover later refunds, cancellations, returns, partial fulfilment or multi-seller scenarios.
4. Reconcile `EBAY-<orderId>` against existing SAP orders **before every run**, including reruns after a timeout. It is placed in `PurchaseOrderByCustomer` (maximum 35 characters), which is **not a unique key**. This workflow does not provide automatic duplicate prevention. A production solution needs a durable order ledger, concurrency control and reconciliation after ambiguous writes.
5. Execute the workflow manually in a non-production environment. Inspect the SAP response for the created `SalesOrder` and confirm the document and items in SAP. Stop on any error and inspect before retrying. No automatic retries are configured.

## Mapping and business assumptions

- `orderId` → `PurchaseOrderByCustomer` prefixed with `EBAY-`.
- Each `lineItems[].sku` → SAP `Material` via the explicit lookup; `quantity` → `RequestedQuantity`.
- `SoldToParty`, sales area and document type come from your configuration. Set the sold-to party for the particular order: the template does not infer customers from eBay usernames or email addresses.
- Header and items are submitted together using `to_Item: { results: [...] }` to `A_SalesOrder`.
- SAP derives partners, shipping address, currency, pricing and taxes from its own master data/configuration. The template does **not** copy the eBay buyer's shipping address, transaction prices, marketplace taxes, shipping charges or payments. Review these gaps before fulfilment or accounting; the created order is not a financial reconciliation of the marketplace sale.
- The CSRF GET uses `$top=0`, requests `x-csrf-token: Fetch` and includes the full response headers. The POST uses the returned token and cookie session. HTTPS and default certificate verification stay enabled.

## Production extensions

Add a durable marketplace-order ledger and explicit exception/reconciliation queue before unattended processing. Design customer and ship-to mapping, pricing/currency/tax handling, inventory and cancellation logic with the business owner. Use least-privilege credentials. Restrict execution-data access and retention because the responses contain customer data and SAP session information. The workflow disables saved successful, failed and manual execution data in its settings; check your instance-level retention, logging and execution policies as well.

## Reference documentation

- eBay getOrder: https://developer.ebay.com/api-docs/sell/fulfillment/resources/order/methods/getOrder
- eBay OAuth user tokens: https://developer.ebay.com/api-docs/static/oauth-auth-code-grant.html
- SAP Business Accelerator Hub (search Sales Order (A2X), OData V2): https://api.sap.com/api/API_SALES_ORDER_SRV/overview
- n8n HTTP Request: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.httprequest/
