Amplify Integration

Getting Started with Amplify Integration – Parse JSON Data

Getting Started with Amplify Integration - Parse JSON Data

In this blog post, we’ll look at one way to easily parse JSON data returned from an HTTP/S Client call or an HTTP/S Server trigger.

This blog post is the fourth 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 on-line documentation for Amplify Integration here and you can register for a free Introduction to Amplify Integration on-line course at Axway University here.

In order to follow this blog post you will need access to Amplify Integration.

You will also need Postman or be able to issue Curl commands to make an API call to the integration.

Create an integration

This post is a continuation of the Getting Started with Amplify Integration – HTTPS Server Connection blog post, so make sure to review the instructions there and create the integration if not already created.

In the prior blog post, the body of the API POST call that triggered the integration contained a JSON object shown below:

{
  "fname": "Leor",
  "lname": "Brenman",
  "status": "active"
}

However, the body is a stringified version of the JSON object shown above and usually we will want to extract properties from an HTTP/S Server body or HTTP/S Client response. Therefore, we need to JSON parse the body.

There are at least two ways to do this in Amplify Integration. In this blog post we’ll cover the Extract method.

JSON parse the HTTP/S Server POST Body using Extract

The Map component is a common component to use for various operations such as mapping data, creating/assigning variables, and transforming data using functions. We will use the Map component to JSON extract the HTTP/S Server Post body to a JSON object (i.e. JSON Parse).

Add a Map component to the integration and expand the bottom panel.

Right click on a variable in the Pipe-out (right hand side) and select Extract.

 

 

 

 

 

Paste the following JSON sample into the dialog box and click Copy Node.

 

 

Right click on a variable in the Pipe-out and select Paste and provide a variable name (e.g. WebhookBody).

 

 

 

Expand HTTPSServerPostOutput in the Pipe-In (left hand side) and click and hold on body and drag your mouse to the new Extract variable you just created (e.g. WebhookBody) in the Pipe-Out and release.

 

 

This effectively JSON parses the API Call/Webhook body into a variable that can be used in your integration.

Click the Save button on the bottom panel.

Test the integration

Now we can test the integration and view the result in the Monitor (as we did in the prior blog post).

 

 

 

You can see that the Extract variable contains the values POSTed in the body of the API call that triggered the flow and these values can be easily accessed in the integration.

Parse an array of JSON objects

Let’s modify our integration to support a modified webhook. Instead of a single user, the body will contain an array of users. For example:

[
    {
        "fname": "Leor",
        "lname": "Brenman",
        "status": "active"
    },
    {
        "fname": "John",
        "lname": "Doe",
        "status": "inactive"
    }
]

So, the Curl command would be:

curl -u "abcd:1234" -H "Content-Type: application/json" -X POST -d '[{"fname":"Leor","lname":"Brenman","status":"active"},{"fname":"John","lname":"Doe","status":"inactive"}]' https://xxxxx.yyy.axway.com:9443/users

However, we’ll need to modify our Extract variable since it is not an array of user objects but just a single user object.

Disable the integration using the toggle switch and open the map step.

Delete the connection between HTTPSServerPostOutput->body and the Extract Variable (e.g. WebhookBody) by clicking on the trash can next to the Extract variable. Right click on the Extract variable and select Delete.

 

 

 

 

Recreate the Extract variable using the JSON array above and make a connection to it from the HTTPSServerPostOutput->body as you’ve done before.

 

 

 

Enable and trigger your integration using the curl command above.

View the transaction in the Monitor and note the two users in the JsonArray in your Extract variable.

 

 

Pro Tip #1: Instead of switching between the Designer and Monitor, Open the Monitor in its own browser tab.

Summary

In this blog post, we learned one way to easily parse JSON data from an HTTP/S Server or Client call using an Extract variable. We parsed a JSON object and an array of JSON objects.

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.