Skip to main content

Order Fulfillment with SMS Notification

In the following recipe, we will walk through a flow where a merchant has marked an order fulfilled through their Order Management System (OMS). Conscia is listening for a webhook from the OMS, and marks the commerce order fulfilled and sends an SMS notification to the shopper letting them know their order is on the way. We will use Twilio and Elastic Path Commerce Cloud APIs as well as a Postman call to simulate a webhook event from an OMS.

Overall Orchestration Flow

Here is the flow that we will be modeling in the DX Engine:

  • The merchant fulfills the order, triggering a webhook with the order status and shipping information.
  • A Conscia listener hears the event and triggers:
    • Elastic Path to update the order status to Fulfilled, and
    • Twilio to send an SMS to the shopper with shipping information.

alt_text

Mapping Out Orchestration Components, Templates, and Listeners

The Order Fulfilled listener invokes the Order Fulfillment Template once the merchant has fulfilled the order and passes the necessary Context values through the engineRequest field on the listener:

"engineRequest": {
templateCode": "epcc-order-fulfilled",
"context": {
"epcc_orderId": "`body.orderId`",
"status": "`body.status`",
"shipping_method": "`body.shipping_method`",
"tracking_number": "`body.tracking_number`",
"edd": "`body.edd`"
}
}

The Order Fufillment Template consists of the following Components and Context values:

alt_text

Orchestration Flow

When the merchant marks the order fulfilled in their order management system, the order management system will emit a webhook containing the order id, status, and shipping information.

In Conscia, we have created an Order Fulfilled listener waiting for this order fulfillment event. It's looking in particular for the order id and status, and then triggering the Order Fulfilled Template.

  • Elastic Path Fulfill Order: With the order id passed in the webhook payload from the OMS, we can update the order status in Elastic Path and mark it fulfilled. We verify in the trigger conditions that the status coming from the OMS is in fact "fulfilled" before running this component. If you have set up additional custom fields on the Elastic Path order to hold shipping information, you can pass that in this API call as well.

  • Twilio Send Order Fulfilled Message: Using the information provided by the webhook as well as the customer name and phone number retrieved from Elastic Path, we can send a text notification to the customer letting them know that their order has been fulfilled and how to track it. Twilio sends back a "queued" status and you may want to implement another listener to wait for the successful delivery message and troubleshoot if it fails.

DX Engine Configuration Details

You will need to configure a connection to Twilio and to Elastic Path Commerce Cloud.

Below are instructions on how to configure the two connections, the listener, and each of the Components discussed above.

Create a Connection to Twilio

  • Navigate to the Connections page (Settings --> Connections).
  • Click the Configure Connection button.
  • Enter the following and click Submit:
FieldValue
Connection Codetwilio-resource-connection
Connection NameTwilio Message Resource Connection
ConnectorUniversal API Connector
Base URLGet value from: Literal
https://api.twilio.com/2010-04-01
Base HeaderHeader: Authorization
Value (JS Expression): 'Basic ' + secret('twilio-basic-creds-btoa')

Twilio requires your credentials to be Bas64 encoded. You can store the encoded authorization token in a Conscia Secret and refer to it from the Connection header.

Create a Connection to Elastic Path Commerce Cloud

  • Navigate to the Connections page (Settings --> Connections).
  • Click the Configure Connection button.
  • Enter the following and click Submit:
FieldValue
Connection Codeepcc-connection
Connection NameElastic Path Commerce Cloud Connection
ConnectorUniversal API Connector
Base URLGet value from: Literal
https://useast.api.elasticpath.com

Create a Listener to listen for the order validated webhook

To create a listener you will need to make a direct API call to DX Engine.

POST https://engine-staging.conscia.io/api/listeners

{
"listener": {
"listenerCode": "order-fulfilled",
"name": "Order Fulfilled",
"sync": true,
"endpointRequestSpec": {
"methods": ["POST", "PUT"]
},
"engineRequest": {
"templateCode": "epcc-order-fulfilled",
"context": {
"epcc_orderId": "`body.orderId`",
"status": "`body.status`",
"shipping_method": "`body.shipping_method`",
"tracking_number": "`body.tracking_number`",
"edd": "`body.edd`"
}
},
"endpointResponse": {
"status": 200,
"body": {
"epcc_trx_response": "`engineResponse.components['twilio_sms_response']`"
},
"headers": [
{
"header": "content-type",
"value": "application/json"
}
]
}
}
}

The mocked webhook event looks like this:

POST https://engine-staging.conscia.io/api/experience/_listener/:listenerLocator/:listenerUuid

Body:

{
"orderId":"48f24697-f51f-4dd3-a21c-34f6d14aa393",
"status":"fulfilled",
"shipping_method": "UPS",
"tracking_number": "LZ243019839US",
"edd": "2024/03/26"
}

Create a Component to fulfill the order in Elastic Path

  • Navigate to the Experience Components page (Manage Experiences --> Components)
  • Click the + Add Component button.
  • Enter the following and click Submit:
FieldValue
Component Codeepcc-fulfill-order
Component NameEPCC Fulfill Order
No RulesChecked
Component TypeConscia - Universal API Connector

The DX Engine will create and prepare the Component for further configuration. You should see the new component appear in the Component listing.

  • Click Edit.
  • Enter the following and click Submit:
FieldForm TabValue
ConnectionMainElastic Path Commerce Cloud Connection
Webservice PathMainGet value from: JS Expression
/v2/orders/${contextField('epcc_orderId')}
MethodMainPOST
HeadersMainHeader: Authorization
Value (Context Field): EPCC Client Credentials Token
HeadersMainHeader: content-type
Value (Literal): application/json
BodyMainGet value from: JS Expression
{"data": {"type": "order","shipping": "fulfilled"}}
Trigger ExpressionConditionscontextField('status') === 'fulfilled'

Create a Component to send an SMS from Twilio

  • Navigate to the Experience Components page (Manage Experiences --> Components)
  • Click the + Add Component button.
  • Enter the following and click Submit:
FieldValue
Component Codetwilio-send-order-fulfilled-message
Component NameTwilio Send Order Fulfilled Message
No RulesChecked
Component TypeConscia - Universal API Connector

The DX Engine will create and prepare the Component for further configuration. You should see the new component appear in the Component listing.

  • Click Edit.
  • Enter the following and click Submit:
FieldForm TabValue
ConnectionMainTwilio Message Resource Connection
Webservice PathMainGet value from: Literal
/Accounts/{{Account SID}}/Messages.json
MethodMainPOST
HeadersMainHeader: Content-Type
Value (Literal): application/x-www-form-urlencoded
BodyMainGet value from: JS Expression
'To=' + componentResponse('epcc-fulfill-order').data.shipping_address.phone_number +'&From=+18316619576&Body=Your order #' + componentResponse('epcc-fulfill-order').data.id + ' has been fulfilled! ' + contextField('shipping_method') + ' Tracking number: ' + contextField('tracking_number') + ' Estimated Arrival: ' + contextField('edd') + ' Love, TheShop'

References