Extract a specific piece of data from an HTTP API request

Hi,

I have a scenario where I am trying to extract a specific piece of data from the Output of an HTTP module (API call).

The specific piece of data I am trying to extract is “message” as shown below.

HTTP MODULE OUTPUT:
Screen Shot 2023-08-01 at 2.38.26 PM

The “message” data shows up in the output of the HTTP module but whenever I try to map to that field from another Module, I get an error that not data was found.

PARSE JSON MODULE:

As you can see below, I used a PARSE JSON module to split the Output of the HTTP module even more, and I believe the error is due to the fact that the exact location of “message” changes every time.

The “message” is always found when type=text, but it can be found in a different “trace” collection every time. So it could be #1, #2, #3, or #4 and I don’t always know which one it’ll be.

SET VARIABLE MODULE:

My solution is to set a Variable using the output of the Parse Data module.

However, I’m not sure I’m getting the logic right.

It should be something like this, where the only variable that determines where the message can be found is when text=type.

Can someone please help me come up with the proper logic to reliably extract this data?

Also, is there a simpler way to do this kind of logic with less modules or in the HTTP module itself?

Thanks for the help.

Hi @John2

It appears that you have utilized the map function incorrectly.

Kindly review the following example I have created to address your requirement.

Input:
image

Input to specific data:
image

Output:
image

You have two options: either you can directly map the data, but keep in mind that ‘trace’ is an array with potentially multiple data points. Therefore, use the map function as demonstrated above.

MSquare Support
Visit us here
Youtube Channel

1 Like

Thank you for the response.

You helped me get on the right track.

Here is the logic that ultimately got me what I was looking for.

I needed to map to the Collection’s “payload.message” when the Type was equal to “text”

Here is the output. (contents of the message are not related)
Screen Shot 2023-08-02 at 1.38.21 PM

2 Likes

Hi @John2 :wave:

just thought I’d jump in and hype you up about this great solution you found with @Msquare_Automation’s help. :star_struck:

Thank you very much for keeping the community in mind and coming back to us with your ideas. We appreciate it.

Keep up the great work! :muscle:

1 Like