1. Knowledge Base
  2. Martini
  3. API design & implementation

How to integrate a RESTful API with a SOAP API

This downloadable demo will show you how to integrate a RESTful API with a SOAP API

SOAP is a protocol that is often used as the interface for legacy systems and commonly with ERP systems.

SaaS applications will typically offer a RESTful API. Integrate SaaS with a legacy system or ERP system that uses a SOAP interface is a common challenge.

In this article we will show to integrate a RESTful API with SOAP.

The use case for this demo is when orders are created in a Demo ERP System they should be sent to an Inventory System for dispatch. In this demo the ERP System uses a SOAP interface and the Inventory System a REST API.

Watch this downloadable demo in action

Line by Line: How this "REST to SOAP API" Demo works

Placing an order in the Demo ERP UI

The workflow starts by placing an order in the ERP API. Upon placing the order, the Scheduler Endpoint:

\\demo005-rest-to-soap\Endpoints\check-pending-orders

endpoint-check-pending-orders

that is polling in the background will trigger the service:

\\demo005-rest-to-soap\code\...\scheduled_services\OrderChecker.

service-orderchecker

The OrderChecker service includes several other services that were machine-generated when consuming the ERP Soap API and Inventory REST API using the Consume API wizard. Upon completing the Consume API wizard a service is machine-generated for every operation in both APIs. All of the machine-generated services created from consuming these APIs are available in the folder:

\\demo005-rest-to-soap\code\demo005\services_imported

Some of these machine-generated services were then included in our OrderChecker service by dragging and dropping them from the ..\services_imported folder referenced above. The machine-generated services included in the OrderChecker service are:

  • Line 3: SelectAllOrder
    This service gets all orders from the ERP SOAP API. When the OrderChecker service is invoked, it will pull all the orders from the ERP API.
  • Line 7: SelectAllOrderLine
    This service gets all order lines from the ERP SOAP API. For each order, it will also get all the order lines associated with it.
  • Line 12: DemoApiInventoryServiceSkuSelectSKUByProductCode
    This service gets SKU records based on a product code from the Inventory REST API. The product code from the order line will then be checked.
  • Line 16: DemoApiInventoryServiceDispatchslipsPutDispatchSlips
    This service creates a pending dispatch slip for a given SKU from the Inventory REST API. Once the SKU in the Inventory has been found, it will get the sku_id, and use it to create a dispatch against it using this service.
  • Line 18: UpdateOrder
    This service updates an order in the ERP SOAP API. Once the dispatch slip has been created, it will update the status of the order to In Process in the ERP API.

Updating the order status in ERP API

The Scheduler Endpoint \\demo005-rest-to-soap\Endpoints\sync-dispatched-orders is also being polled in the background. This endpoint checks the dispatch slips from the Inventory API, and checks if the dispatch has been shipped. The endpoint polls every 15 seconds, and triggers the service:

\\demo005-rest-to-soap\code\...\scheduled_services\SyncDispatchedOrders

This service calls to several Services generated from ERP (SOAP) and Inventory (REST) APIs that are used as a Function to pull the dispatch slips and update the order status in the E-Commerce API

  • Line 3: rest.inventoryApi.dispatchSlips.DemoApiInventoryServiceDispatchslipsSelectDispatchSlipsByReference \ This is a Service generated from Inventory API and is used as a Function to pull all the dispatch slips with shipped status in the Inventory API.
  • Line 4: soap.erpApi.SelectAllOrder \ This is a Service generated from ERP SOAP API and is used as a Function to pull all the order records in the ERP API.
  • Line 6: io.toro.martini.ArrayMethods.find \ This Function is used to find an order record that matches the closure condition. The closure condition used in this Function is the dispatch_ref from the shipped dispatch slips from the Inventory API. Once the order has been found, it pulls that order record and then passes it to the next step.
  • Line 8: soap.erpApi.UpdateOrder \ This is a Service generated from the ERP SOAP API and is used as a Function that updates an order record in the ERP API.

Syncing SKU stock levels

The Martini Scheduler Endpoint \\demo005-rest-to-soap\Endpoints\sync-sku-stock polls every 5 seconds, and triggers the service \\demo005-rest-to-soap\code\demo005\services\scheduled_services\martiniEndpointServices\SyncSku. This service calls to Services used as a Function to pull SKU stock levels from Inventory API, and update the stock levels in the ERP using these levels.

  • Line 3: rest.inventoryApi.sKU.DemoApiInventoryServiceSkuSelectAllSKU \ This Function pulls all the SKUs in the Inventory API.
  • Line 7: soap.erpApi.SelectAllSKU \ This Function pulls all the SKU from ERP API. The SKUs returned by this function will be then used to search for a matching SKU record from Inventory API
  • Line 6: io.toro.martini.ArrayMethods.find \ This Function is used to find the ERP SKU that matches the product code from Inventory API. If the SKU is found, SKU data will be pulled and mapped to the foundSku in the output for the next step to use.
  • Line 8: soap.erpApi.UpdateSKU \ This function is used to update an SKU in the ERP API.
    • When this service is triggered by the Martini Scheduler endpoint, It will pull all the SKUs in the Inventory API, and the SKUs from the ERP API
    • Each Inventory SKU will then be iterated, and for each Inventory SKU, look for the corresponding SKU in the ERP API using the product code(Line 6).
    • If the SKU is found, the current stock levels of the SKU in the Inventory API will be sent to the ERP API, updating the current stock levels in the ERP API

Logging the transactions to Tracker

  • Logging service transactions are added to the services used in this demo by using Tracker functions
  • These logs can be used for auditing what took place during the execution of services being triggered during the application flow.
  • To access the Tracker UI, look for a magnifying glass icon in the menu bar on the top-right corner of the Martini Desktop UI.
  • The Tracker functions are used and placed strategically before or after a certain function is executed
    • Tracker.addDocumentState - This function is used for adding States in a Tracker document.
    • Tracker.addDocument - This function is used to create a new Tracker document. In contrast to Tracker.addDocumentState, this function is the parent document and must exist first before State can be created. Additionally, this function is only used once in the whole application flow for this demo, and it’s added on the entry point of this demo which is the PayOrder service
  • Sample usage:
    • Open the OrderChecker service located at \\demo005_rest_to_soap\code\demo005\services\scheduled_services
    • In the OrderChecker service, the addDocument function is on line 15 once the service has fetched the order line items to be added in the dispatch slip.
    • After the dispatch slip has been created, additional states are added to the document once the dispatch slip has been updated and the order is updated to In Process status