cancel
Showing results for 
Search instead for 
Did you mean: 

Help with HttpRequestViaScript in Automation Pilot

Ron_Hagan
Product and Topic Expert
Product and Topic Expert
0 Kudos
225

Hi,

I'm trying to use HttpRequestViaScript to execute a POST request to get a bearer token for an API using Automation Pilot but I'm having issues populating the Parameters correctly.

As an example, if the authorization is Basic Auth, what should go in "authorizationHeader"?

Also, in "headers", I would like to populate things like the Content-Type and (if necessary), the grant_type.

Examples of using HttpRequestViaScript that I've seen don't really show how to populate those parameters. 

Any specific examples would be greatly appreciated.

My end goal is to create a command that not only retrieves the Bearer Token for the API but then passes it to another HttpRequestViaScript for another HTTP request.

If any more information is needed from me, please let me know.

Thanks in advance!

Ron

View Entire Topic
BiserSimeonov
Product and Topic Expert
Product and Topic Expert

Hi Ron! 

First, thanks for looking into SAP Automation Pilot and I hope you like the tool! 

Some context: to speed up the onboarding into SAP Automation Pilot we have created a public Github repo with sample end-to-end use cases and ready to import commands plus a detailed explanation on trigger these. Please find a link to this repo here: https://github.com/SAP-samples/automation-pilot-examples/tree/main?tab=readme-ov-file#sap-automation...

You can find out more details on how import any of these sample end-to-end commands here: https://github.com/SAP-samples/automation-pilot-examples?tab=readme-ov-file#how-to-use

Having said that, going to your specific question . How I get it - you want to generate a token and then use the token already generated in your next executor within the Automation Pilot command. You are checking the provided command about "HTTP Request via Script" which is used when working with synchronous HTTP APIs and request to such APIs might take minutes to complete. However, I think HttpRequest  provided command will be fine for your use case. To explore a similar use case where exact these steps are covered (generating a token and using it within the next executor) , please see this example: https://github.com/SAP-samples/automation-pilot-examples/tree/main/check-hana-cloud-availability#che... 

Note: you can import this example in your Automation Pilot tenant and explore it, as an expected result you should get this end to end automation flow: 

BiserSimeonov_0-1723530336751.png

As you will see, more interesting for you should be these two executors: 

  • getToken
  • pingHanaCloud (where the token is used to call the HANA Cloud Metrics API and fetch data for the HANA Cloud DB in question) 

For both executors the method is "GET" but you can change it to "POST" as per your specific needs. Moreover, to modify the request, simply click on the "edit" link and then you can change / add more parameters, see below: 

BiserSimeonov_1-1723530584110.png

BiserSimeonov_2-1723530641198.png

I have described this use case in details in this blogpost as well: https://community.sap.com/t5/technology-blogs-by-sap/automated-availability-check-for-sap-hana-cloud... 

I hope also these details will help you to setup the needed automation flow. In case you face any troubles please reach out to me directly at biser.simeonov@sap.com and if I can help will do so (if not - I can schedule a deep dive with our support team). 

Kind regards,
Biser

Ron_Hagan
Product and Topic Expert
Product and Topic Expert
0 Kudos
I was able to successfully execute both the bearer token request and the GET request using HttpRequest! Thank you!