Monday 2 August 2021

How to Integrate GraphQL API with Blue Prism

 GraphQL API - Blue Prism Integration

This post discusses how to integrate GraphQL API with Blue Prism using a sample graphQL API and Utility-HTTP VBO in Blue Prism.

Consider the following API: 
https://api.spacex.land/graphql/

First Let's try fetching simple data from the API. For this, we need the AddressURL, method, body.
In this example API, there are some details about rockets, that we are going to query using the format defined by the GraphQL API.

GraphQL API allows us to fetch the required fields by specifying the field names as a nested string containing curly braces ({,}), which represents the hierarchy, as a  query parameter inside the body part of the request and calling the POST method of HTTP on the URL, is shown below as Input.
The response of the above request is shown as output below

For Example:

Input:                    


Output:


To Simulate the above API request in Blue Prism, I am making use of Utility-HTTP VBO.
Set the input parameters as follows:
Action: Utility-HTTP
Page Name: Post JSON
    Input Parameters:
  •    AddressURL:  https://api.spacex.land/graphql/
  •   JSON: payload
Output Parameters:
  •   Result
Here the payload variable is the data item that holds the GraphQL Query. And the query is supposed to be passed as JSON data.
To represent the hierarchy of the database objects and to distinguish between table names and field names and properties, we use multiline text.
As this query parameter and its value is passed in JSON format, we need to explicitly indicate the newline characters using escape sequences like \n.

And also to pass the JSON data in a calculation stage of blue prism we need to escape the double quotations as well. This can be done by adding two successive quotes.

{
    "query":"{
                          rockets {
                                country
                                description
                                diameter {
                                               feet
                                              meters
                                               }
                                          }
                            }"
}

We need to escape all the new lines and double quotes present in the query using \n and "" and the query should be written in BluePrism as:



























Following is a sample process to get the data from Graph QL API.


Set Parameters Multi calc stage looks like this:





















Pass the Address URL and Payload values as Inputs to the Post JSON Action Stage. Set the output parameters to receive the response.


Now Set next stage at Start Action and run the process. The output will be stored in the Result data item in the JSON format as shown below.

API Response:




Thank you!

No comments:

Post a Comment

How to Integrate GraphQL API with Blue Prism

 GraphQL API - Blue Prism Integration This post discusses how to integrate GraphQL API with Blue Prism using a sample graphQL API and Utilit...