How To Use UiPath HTTP Request Activity For A GraphQL API Endpoint?

How to use HTTP Request activity for a GraphQL API endpoint?

Error Description:

{

"errors" : [ {

"message" : "Invalid JSON payload in GraphQLAuth POST request.",

"errorType" : "MalformedHttpRequestException"

} ]

}


Resolution:
Note:
This is an internally tested example (using a Visual Basic project) to solve the issues with the GraphQL API endpoint while using the UiPath HTTP Request activity. Adapt it accordingly based on the internal requirements.

Assume that the HTTP Request activity is already tried and in the end, an error message is thrown as

{

"errors" : [ {

"message" : "Invalid JSON payload in GraphQLAuth POST request.",

"errorType" : "MalformedHttpRequestException"

} ]

}

To solve the issue, perform the below steps:

  1. Create a Visual Basic project in Studio
  2. Add in dependencies the UiPath.WebAPI.Activities[1.9.2] (or use the latest package version available)

  1. In the Main.xaml sequence -> Activities -> add a HTTP Request activity

  1. In the HTTP Request activity add at the beginning only the End point URL (you will add the necessary information after that) -> OK

  1. Go to the GraphQL Client -> select a request that is to be made -> right-click in the GraphQL Client web browser page -> click on Inspect -> Network -> enable Preserve log checkbox (this will allow you to troubleshoot from back-end your GraphQL endpoint requests)

  1. In the GraphQL Client perform a Send Request action

  1. In the Inspect -> Network -> click on the Name that performed the POST request -> Verify the Headers section

From there extract these details:

In this example considered ( here replaced xxx values due to security restrictions, it will be different information details):

Request URL: https://api.reportresults.xxxxx.edu/

Request Method: POST

Accept: application/json

Authorization: xxxxxxx-xxxxxx-xxxxxx-xxxx-xxxxxx

Content-Type: application/json

  1. In the Inspect -> Network -> click on the Name that performed the POST request -> Verify the Payload section -> copy the non parsed string from Request Payload

From there extract the payload details:

In this case it will be

  • {"query":"{\n \n getReport(report_number: \"2141438171\") {\n report_date\n \n }\n}","variables":{},"operationName":null}

and after the String transformation, your Payload request for Studio HTTP Request activity should have this form:

  • "{""query"":""{\n \n getReport(report_number: \""2141438171\"") {\n report_date\n \n }\n}"",""variables"":{},""operationName"":null}"

  1. With all the needed details in place, go back to Studio and configure the HTTP Request activity in the Properties tab.

AcceptFormat: ANY

Endpoint: should be already populated with your address "https://api.reportresults.xxxxx.edu/"

Method: POST

Body: "{""query"":""{\n \n getReport(report_number: \""2141438171\"") {\n report_date\n \n }\n}"",""variables"":{},""operationName"":null}"

BodyFormat: application/json

Headers (add three Names of type String as bellow):

Authorization: "xxxxxxx-xxxxxx-xxxxxx-xxxx-xxxxxx"

Accept: "application/json"

Content-Type: "application/json"

In the Output (for monitoring purposes and manipulating your data), you can create three variables for Headers: Headers, Result: Result, StatusCode: StatusCode

  1. For monitoring the execution, use some Write Line activities and monitor the values for the output variables.