In this blog post, we’ll look at creating, using and mapping variables in your integration. We’ll use the Getting Started with Amplify Integration – OpenAPI Connection to REST APIs as a starting point. If you have not reviewed this blog post, please do so now.
This blog post is the eighth in the “Getting Started with Amplify Integration” blog post series and builds on the knowledge gained prior. As such not all steps will be explicitly called out since they are already covered in prior posts.
You can view the technical online documentation for Amplify Integration here and you can register for a free Introduction to Amplify Integration online course at Axway University here.
In order to follow this blog post, you will need access to Amplify Integration.
Create an integration
Let’s retrieve some data from the Petstore API and use variables to store processed data from that response.
Use the integration from Getting Started with Amplify Integration – OpenAPI Connection to REST APIs as a starting point.
Test your integration to see that you are receiving data.
Array size calculation
Let look at how we can use variables and map functions to determine the number of pets returned in the response. In other words, the size of the response
array property of the API call output shown in the last screen shot above. Note that in Amplify Integration, an array of JSON objects is actually referenced as a list. We’ll do this three different ways.
First we’ll create three integer variables to store our array/list size.
- Expand the OpenAPI Client component bottom panel and right click on a variable in the Pipe-out and select:
Add Variable -> Integer -> Add After
and enter a variable namearraysize1
. - Repeat two more times and name the other two variables:
arraysize2
andarraysize3
Note that next to each variable is the component name that the variable was created in. This is useful for determining where variables were created later on in the integration
Now let’s use the most straightforward method of calculating an array size and that is to use the SizeOfList
function in a Map component.
- Add a Map component to the canvas and expand the bottom panel
- Click the +fx icon in the middle of the panel
- Select
List
and scroll down to selectSizeOfList
Note the extremely large number of functions available to integration developers. The complete list can be found in the online docs here
- Expand the
findPetsByStatusOutput
variable in the Pipe-in (on the left hand side) and drag a line fromresponse
to thearray
input of theSizeOfList
function and drag a line from thesize
output of theSizeOfList
function to thearraysize1
variable in the Pipe-out (right hand side) - Click the Save icon
Test the integration by clicking on the Test button and viewing the transaction Map step and see the value in arraysize1
.
Note that the Petstore API can return a different number of pets than what is shown above
Another array size calculation
Let’s try to calculate the number of pets two other ways. We’ll loop over the response array and increment a counter. We’ll also discover that loops contain an iteration variable, iterator
, that we can leverage. Note that since we already calculated the size using the SizeOfList
function, the rest of this exercise is purely academic for the purposes of discovering other aspects of the platform.
- Add a For-each Loop component and set the configuration to the response array
- Add a Map component inside the Loop and expand the bottom panel
- Drag a line from
iterator
in the Pipe-in (left hand side) toarraysize2
in the Pipe-out (right hand side)
- Click the +fx button and add a Math
IncrementInts
function - Drag a line from
arraysize3
in the Pipe-in to IncrementIntsnum
and from IncrementIntsoutput
toarraysize3
in the Pipe-out - Click Save
- Since we are incrementing
arraysize3
we need to initialize it. Go to the OpenAPI Client step and setarraysize3
to 0 and click Save
- Since the
iterator
will always be 1 less than the loop count (array indices start at 0 and not 1) we need to incrementarraysize2
by 1 after the loop completes - Add a Map step and use the
IncrementInts
function to incrementarraysize2
Test your integration and check the loop step in the transaction in the Monitor.
Pro Tip: USE LABELS!!!! As we add more and more components to the integration it’s harder to recall what each component does during design and debug. Component labels make this much easier! Use them!
Summary
In this blog post we looked at using, mapping and creating variables in your integration. We determined the size of an array in an OpenAPI response three different ways and discovered how to use functions in Map components.
In future blog posts, we’ll build on our knowledge and explore more of the features of Amplify Integration to create no code integrations.
Dive deeper into what’s possible with Amplify Integration.