Question

Need to fetch job id from http request output

  • 27 October 2023
  • 2 replies
  • 59 views

Badge +6

I am using http request in workflow which is in running in loop to run vm level backup. as an output it returns output for each http request as show below 

[{ "taskId":250501,"jobIds":[ "21035126" ] },

{ "taskId":250502,"jobIds":[ "21035127" ] 

 

I want to fetch the jobids from this and add it is list. How can this be achieved.


2 replies

Userlevel 5
Badge +13

Hi @Rahul Nair,

 

You can use a ‘Script’ activity (which can be found under the Utilities section) to parse the string for you and extract the Job ID.  The Script activity will allow you to leverage either Java or JavaScript code to do this. 

 

You can leverage Java methods such as trim / split to isolate the job ID from the full output of your HttpClient activity.  There are many online resources (such as w3schools / stackoverflow) that have good examples to follow if you’re unfamiliar.  Have the script ‘return’ that value, so that the job ID is what’s contained in this Script activity’s output.

 

Once your Script activity is returning the Job ID, you can feed that output into an AddToList activity.

 

-Brian Bruno

 

 

Badge +1

Hello Rahul,

 

in addition to Brian answer - which is perfect - you can also change the response to XML instead of JSON and use XPath - it’s way easier and using standard activities. 

Let us know.

Mattia P

Reply