We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+

Quick Start

Connecting your first SaaS applications

In this guide, you’ll be leveraging the work created from guides 1, 2, and 3 of the quick start series to learn how to use Anypoint Design Center’s flow designer to:

  • Create a service that runs on a schedule.
  • Gather and combine data from two data sources.
  • Push enriched data into another system to bring it to relevant stakeholders.

Why integrate APIs with Anypoint Design Center

Flow designer in Anypoint Design Center is optimized for implementing common integrations in a web-based, graphical interface. Some of the benefits of flow designer include the ability to:

  • Quickly leverage connectors auto-generated from an API specification via REST Connect.
  • Easily click and add connectors to send/receive data to/from systems.
  • Visually map data using DataSense.
  • Fast and easy application deployment to cloud.

Get set up

  1. Sign up for a free 30-day Anypoint Platform account if you haven’t done so yet. You'll need an account to access existing assets in Anypoint Exchange and create Mule Apps in flow designer.
  2. Get a Slack API token.

Bridging APIs with Design Center

Within Design Center, you can build a Mule application to integrate two APIs together and drive real business processes easily. The service you're about to create will perform the following tasks on a scheduled date/time:

  1. Retrieve all leads from Salesforce.
    • These leads were auto-generated from a customer purchasing a product that has been campaigned with upsell potential.
  2. Use the product ID to retrieve more details about the product from a separate API.
  3. Aggregate leads and products data, to help members of the sales team have more context when engaging prospects.
  4. Convert the data to a CSV file.
  5. Upload the data to a specific Slack channel and/or individuals.

Creating a new Mule app

To start off, navigate to Anypoint Design Center and create a new Mule application project:

  1. Select the Create button → Mule Application.
  2. Fill out the name for your application (e.g. "Weekly-Product-Leads").
  3. Press Create.

Create a new Mule application in Flow Design in Design Center

Adding a scheduler trigger

After you create the project, you'll be taken to the canvas of your new Mule Application's first flow. In this canvas, you can add different components to perform a variety of processes to help accomplish your tasks.

Since this Mule application will be running on a schedule, add the Scheduler component as your trigger:

  1. Click the Trigger button to add a new trigger.
  2. Select Scheduler from the modal that pops up.
  3. Configure your Scheduler with the following values to have the flow run immediately once the app starts, and continuously run every 5 minutes:
    • Scheduling Strategy: Fixed Frequency
    • Time Unit: Minutes
    • Frequency: 5
    • Start Delay: 0
  4. Click the X on the top right of the modal to close and save.

Adding scheduler trigger to flow designer

Adding a Salesforce query

In order to run a Salesforce query of all new leads, you're going to add the Salesforce Connector onto the canvas, select the corresponding operation, and configure it. In the canvas:

  1. Click the + to add a new component in the flow.
  2. Scroll and select the Salesforce Connector.
  3. Select the Query operation.
  4. This will present you with the operation configuration window. Click the Set up link to configure the connector itself first.
  5. Enter/select the following connector configuration:
    • Connection Type: Username Password
    • Username: mulesoft
    • Password: mulesoft
    • Security Token: {{LEAVE EMPTY}}
    • Autorization URL: http://salesforce-emulator.cloudhub.io/services/Soap/u/41.0
  6. Click Test to ensure the configuration is correct and works, then Save.

SalesForce connector configuration

This is a basic emulator service and not a functional Salesforce instance. Any operations and requests that are different from those in this guide will result in an error response.

Next, you'll need to configure the Salesforce query operation by entering the SOQL query, which will return several fields from leads:

  • Enter the following for the fields:
    • Salesforce Query: SELECT Id,FirstName,LastName,Company,Email,Phone,Product_Purchased__c FROM Lead
  • Press the X on the top right of the modal to close and save the changes.

SalesForce query configuration

Assign a variable

To create and set a variable, you need to add the Transform module and create a variable that contains all the data you want to export to Slack:

  1. In the canvas, click the + button.
  2. Select Transform.
  3. Click the down arrow next to where it says Output payload, click the pencil icon to edit the transformation Type.
  4. Select "vars" from the Type dropdown and fill out the field:
    • Name: productLeads
  5. Click Save.
  6. Click the Script tab on the bottom of the modal to set the transformation code using the DataWeave code below:

Adding "//" allows the user to add a comment, which isn't read by the DataWeave engine, but is meant to help anyone reading the code.

// Specify the language as DataWeave 2.0
%dw 2.0

// Define the output data type. 
output application/csv

// Denote the end of header section and beginning of body where transformation code is written
---

// Initialize the variable as an empty list (array)
[]

Creating a variable with DataWeave

Note the section on the left contains the data structure for all the input variables coming into the current transformer from the previous processes using DataSense.

Halfway checkpoint

The output of the Salesforce Connector is an Array of Leads, and each element in that list of leads contains the field "Product_Purchased__c," which actually contains the Product ID that you need to use. This setup results in the following logical flow:

  1. Iterate through the list one at a time and look at each lead.
  2. Grab the product ID from each lead and use it to get the product details from the necessary product API.
  3. Add the user and product details to the array variable you created earlier.
  4. Go back to the first step and repeat until all leads are iterated through.
  5. Push the array to Slack.

Iterating through leads

To iterate through the array (list) of leads, you need to add the Foreach scope. Since the variable that contains the array of leads is "payload" and we want to go through just one lead at time, we need to add and configure the Foreach:

  1. In the canvas, add a Foreach component.
  2. Apply the following configurations:
    • Collection: payload
    • Batch Size: 1
    • Root Message Variable Name: rootMessage
    • Counter Variable Name: counter

Foreach scope configuration

Reusing existing assets

Since there is already a product API with product information available in Anypoint Exchange's public repositories (or yours if you've designed, developed, and deployed your own already), you can discover the API and consume the service with minimal work and almost no code. The next step is to get the product information from this service:

  1. Add the component "DevRel-Quick Start Product API" inside the Foreach scope.
    Click the Set up link to configure the connector service before configuring the operation.
  2. Leave all the fields with the pre-populated configurations except:
    • Username: mulesoft
    • Password: mulesoft
  3. Save the connector’s configuration.

Catalyst Retail Quick Start Edition connector configuration

After you configure the connector, you can now configure the Get Product By Product Id operation. In order to do that, you'll need to add some DataWeave code to dynamically add leads to the existing current lead.  The current lead is currently described by the variable payload.

  1. Press the f(x) to convert the regular textbox to DataWeave function mode.
    • Product Id: payload.Product_Purchased__c

Catalyst Retail Quick Start Edition connector operation configuration

Since the variable “payload” contains the lead data that you need to use later, let's store the product data from the product API in a new variable to avoid overwriting the lead data:

  1. Click the Advanced tab.
  2. Enter the following:
    • Target Variable: product
    • Target Value: payload

Catalyst Retail Quick Start Edition connector operation advanced configuration

While the target value may say "payload," it's actually referencing a temporary local variable that's the output of the returned response from the service. It is not the same as the payload that comes into the connector (in this case, it contains the current lead).

Aggregating data

At this point, you have all the data you need to transform the data into"key : value" pairs that can easily be converted to "column : row" CSV format.

  1. Add the Transform connector to the canvas inside the Foreach scope.
    Change the Output from payload to productLeads by clicking the pencil icon at the top of the Transform connector.
    • Type: vars
    • Name: productLeads
  2. Select Script to manually enter the DataWeave transformation code from below:
%dw 2.0
output application/csv
---
// This sets a default value of an empty array to vars.productLeads just in case it's not set. It will then append the object we want to it.
(vars.productLeads default []) ++ [
    {
        // This is a 1:1 mapping of values from the payload (contains lead data) and product variables
        firstName: payload.FirstName,
        lastName: payload.LastName,
        company: payload.Company,
        email: payload.Email,
        phone: payload.Phone,
        productModel: vars.product.model,
        productPrice: vars.product.price.amount.currencyValue,
        productCurrency: vars.product.price.amount.currency,
        productDescription: vars.product.description
    }
]

 

Uploading to Slack

The last step before testing the integration is to add the Slack connector and configure it.

  1. Click the + button on the right (outside of the Foreach loop).
  2. Select the Slack connector.
  3. Select the operation File - Upload.
  4. Configure the Slack connector first by clicking the Set up link.
    • Select the connection type you wish to use. We recommend selecting 1 - Token Connection for this guide.
    • Get the token from Slack.
    • Paste your token.
    • Click Save.

 

Next, you'll configure the File - Upload operation by filling out the fields as below:

  • Content: vars.productLeads
  • Channels: {{CHANNELS/USERS AS ARRAY OF STRINGS}}
    • e.g. ["account_development"]
  • File Name: "Product-Lead.csv"
  • Title: This week's product leads
  • Initial Comment:
  • File Type: text/csv

If your corporate account doesn't grant you access to generating tokens, you can create a free Slack workspace.

Trying the integration

Now with everything configured and on the canvas, you're ready to run a quick test to make sure it works as expected. To run the application, simply press the green Run button on the header of the page—this will load the Mule application in a temporary workspace.

Run Mule app

Within the Slack channels or direct message to users (depending on what you choose), you'll see a new message show up with the CSV uploaded as an attachment. This will run every 5 minutes, as below:

CSV uploaded to Slack

Setting scheduler to cron

Now that you know that the Mule application works, it's time to wrap up the application by having it run as a cron job every Monday at 8AM in your time zone.

  1. Click Scheduler Connector to open the configuration settings.
  2. Find a "cron expression builder" using your favorite search engine and paste that into the Expression field.
  3. Write your time zone in Java time zone format.

Configure scheduler as cron job

Deploying your app

Great! Your app is ready for deployment. To deploy the app, it's only a matter of a few clicks to have the service up and running in our CloudHub service.

  1. At the top of flow designer, click the blue Deploy button.
  2. Select the environment to where you want to deploy the application (e.g. "Sandbox").
  3. Enter the application name or leave default.
  4. Click Next.
  5. Change environmental connector settings if you choose to, or leave as is.
  6. Click Deploy!

Next steps

And that’s it, congratulations! You've built an integration that periodically takes data from two API sources, converts the data types, aggregates them together, and then uploads the data to the group that needs it, while barely writing any code!

Try improving your integration by doing the following:

  • Perform more DataWeave transformations—specifically thinking about how to handle no data and setting "default" expressions in order to prevent errors.
  • Check out the Tutorials and How-Tos page to learn more about Anypoint Platform.