# API Recipe Walkthrough

Ready to make your own API recipe? In this guide, we'll walk you through an example using Salesforce.

Our goal is to automate creating an opportunity in Salesforce and then expose it as a REST endpoint. External business partners and internal stakeholders can use this endpoint to access and consume data without requiring access to a Workato account.


# Step 1: Create The Recipe

In this step, you'll create the recipe and select its starting point.

1

Create a new recipe and give it a name.

2

Select a folder to contain the recipe.

3

Click Build an API endpoint as the starting point.

4

Click Start Building.

When the Build an API endpoint starting point is used, Workato will automatically create a recipe with a New API request trigger and a Response to API request action.


# Step 2: Define The Recipe's Trigger

Next, you'll define the request and response structures for the endpoint by defining the New API request trigger parameters. Defining the trigger has two steps:

# Step 2.1: Define The Endpoint's Request Structure

In this step, we'll define the parameters for requests made to the endpoint. The request schema determines the fields that are shown and must be defined when an action is created in the API recipe.

1

Click the trigger to open its Setup tab.

2

Open the Request tab if it's not open already.

3

In the Content type field, select the type of data the endpoint should accept. For example, selecting application/json means the endpoint would expect and accept valid JSON data in a request.

4

In the Request header section, define the parameters that should be in the headers of requests sent to the endpoint.

5

In the Request schema section, define the schema of request bodies sent to the endpoint. You can either upload a sample JSON file or enter the fields manually. You can learn out more about JSON here (opens new window).

In this example, our schema would contain the fields necessary to create a Salesforce opportunity.

# Step 2.2: Define The Endpoint's Response Structure

After you've defined the structure for requests, move on to the endpoint's response structure. The response structure determines the outputs returned by the API recipe and their respective fields.

For example, if you wanted your endpoint to inform users when an opportunity is successfully created, you could add a response (200 - Created) that does that. The response could contain information about the opportunity, such as its ID, creation time, and so on.

You can also define Error responses in this section in case the API recipe action isn't successful.

1

Open the Response tab, if it's not open already.

2

In the Response header section, define the parameters that will be present in response headers sent from the endpoint.

3

In the Response schema section, define the schema of response bodies sent from the endpoint. You can either upload a sample JSON file or enter the fields manually.

In this example, we could add an ID field to represent the ID of the newly created Salesforce opportunity.


# Step 3: Add Steps To The Recipe

Next, we'll add actions to the recipe. As per our best practices for creating recipes, we're going to add these blocks:

  • Monitor - Think of this block as the success response. If actions in it are executed without error, the recipe will end here.
  • On Error - If the Monitor block returns an error, actions in this set will be executed.

# Step 3.1: Define The Monitor Block

1

In the Monitor block, add the desired action. In this example, we'll add an action that creates a new opportunity in Salesforce (Action in an app > Salesforce > New opportunity.)

2

Map the appropriate data to the action. We can manually map the data from the recipe's trigger to the required input of the Salesforce action or use the Group map data to do the mapping for us automatically.

3

After you're finished defining the action(s), click the Return action. Defining the Return action ensures our API endpoint returns a response that indicates if the actions in the Monitor block were successful.

4

To define the Return action:

1

Select a Response. For example, if the opportunity was successfully created in Salesforce, we could select Created.

2

In the Response schema section, map the appropriate data to the schema's fields.

For example, we want to return the newly created opportunity's ID in the response, so we'll map our ID field to the Object ID datapill returned from the Create Opportunity in Salesforce action.

# Step 3.2: Define The On Error Block

The last step is to define the On Error block, which will run if the action(s) in the Monitor block - in this case, that's the Create an opportunity in Salesforce action - are unsuccessful.

Error responses enable your endpoint to provide useful information when something goes wrong, allowing for more targeted troubleshooting.

For example, if the opportunity isn't successfully created due to Salesforce's API experiencing an outage, you could add a response that indicates this.


# Step 4: Save And Test The Recipe

Save and test your recipe as you go! We recommend building recipes in small steps to make it easier to troubleshoot any issues you encounter.


# What's next?

NEED TIP-TOP API PERFORMANCE?

Using the Jobs data retention recipe setting, you can enable zero logging and improve performance for your API recipes. Note that there are some trade-offs.

Check out the Defining data retention for recipes for more info.

Congrats on creating an API recipe! Check out what else you can do with these other resources: