Azure Logic Apps - Parsing Output Header Values

Here's a quick little tip for extracting a value from an HTTP output inside your logic apps.


I've been pulling some records down from Service Now today to automate sending updates to Microsoft Teams (saves me having to visit SNow all the time! - I'll write another post on my approach to this).

One thing I wanted to do was count the number of records returned for any tickets marked as "work in progress".  I had a quick poke around and couldn't see any quick option (I'm sure it's still possible via inline Javascript or similar) although I quickly noticed that the HTTP header output from the Service Now List Records action has a total count. See below:

Why bother trying to count records when the value already exists!


The Logic

After your trigger then initialise a variable, give it a name and then select the according data type. Even though the return is a number, integer didn't work so I altered it to string. You shouldn't specify a value in this initialisation.

In this example I'm using the Service Now module, where the List Records action has an HTTP header output, but you can use any other action that has a header output. See below:

After the HTTP request has completed you'll want to pull that value from the header into the variable you initialised earlier on.

The name will be the name you set in the initialisation and the value is where the magic happens!

Our value here is set from the output from "List Records" (previous action) and then we look into it's header with ['headers'] followed by specifying the attribute we want ['X-Total-Count'].  We can replace this with any one we want to extract.

outputs('List_records')?['headers']?['X-Total-Count']
This is the magic

Check Set Variable Output

Let's run the logic to test it and check the output of Set Variable:

Output from Set Variable

Here we have the exact value stated in the header that's inside the variable. From here we can bring this into any other action when we need it whether Compose, SNow action, Teams post message action etc....

Hope you enjoyed! This neat little trick certainly saved me some time although if you have any tips on counting records/items in Logic Apps please let me know.