SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Send SMS using SAP Cloud Integration while consuming a Twilio API

Learn how to pass parameters with URL encoded form to a HTTP receiver adapter, to send SMS messages using a Twilio API, as a notification that the Order has been successfully created.

Overview

🎓 intermediate 10 min. SAP Integration SuiteIntermediateFree TierCloud IntegrationSAP Business Technology Platform

You will learn

  • How to pass parameters with URL encoded form to a HTTP receiver adapter, to send SMS messages using a Twilio API, as a notification that the Order has been successfully created.
Mariajose Martinez M Mariajose Martinez November 21, 2022
Created by October 28, 2022
Contributors

Prerequisites

Prerequisites

  • You have a SAP BTP account or trial account with access to the SAP Integration Suite.

  • You have completed the previous tutorial Consume a SAP Sales and Service Core API to create Sales Orders using SAP Cloud Integration.

  • You have a Twilio account or trial account. In the Twilio documentation, you’ll see 3 needed URL encoded parameters to be sent to trigger the API call, which are:

    • From <Twilio sender’s phone number>
    • To
    • Body <Body of the message / SMS to send>

    Keep in mind that in fact the recommended way to consume Twilio APIs, is by leveraging its Connector with SAP Open Connectors, as you used in a previous tutorial with Stripe. This exercise is to learn how to do it with a standard HTTP adapter.

Steps

Step 1 Get the Sales Order Id from SAP Sales and Service Core

To continue from the previous tutorial where you configured a SAP Sales and Service Core API to create sales orders, now what you need to get the sales order id and send a SMS with a custom message, consuming the Twilio “create a message” API. Here’s the Twilio API documentation.

  1. Add a Content Modifier task and in the Exchange Property tab, add a new property:

    • Action: Create
    • Name: salesOrderId
    • Source Type: XPath
    • Source Value: /CustomerOrderCollection/CustomerOrder/ID
    • Data Type: java.lang.String

    Like this:

    Get the sales order
    Get the sales order

    Now as you are going to send dynamic SMS with different sales orders Id for every time you run the demo, you need to add a Groovy Script task to configure our new needed Body for the Twilio SMS API.

  2. Add a Groovy Script and create a new script by clicking in the page and plus + icon while selecting the Groovy task:

    Add Groovy script
    Add Groovy script

    Copy and paste this code:

    JavaScript
    import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.HashMap;
    def Message processData(Message message) {
        //Properties
        def properties = message.getProperties();
        salesOrder = properties.get("salesOrderId");
        messageText = ("Thank you for your purchase, your order id is " + salesOrder)
        message.setProperty("encodedMessageText", java.net.URLEncoder.encode(messageText, "UTF-8"));
        return message;
    }

    You should see it like this:

    Add Groovy script
    Add Groovy script

Step 2 Prepare headers and body to send x-www-form-urlencoded data to the Twilio service
+
Step 3 Add the request call to post the message to the Twilio SMS API
+
Step 4 Create Twilio credentials in SAP Cloud Integration
+
Step 5 Test your Integration Flow
+
Step 6 Check your knowledge
+
Step 7 One more time, check your knowledge
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 7
1. Get the Sales Order Id from SAP Sales and Service Core 2. Prepare headers and body to send x-www-form-urlencoded data to the Twilio service 3. Add the request call to post the message to the Twilio SMS API 4. Create Twilio credentials in SAP Cloud Integration 5. Test your Integration Flow 6. Check your knowledge 7. One more time, check your knowledge

Learn more →