Using Local Variable In Post-Response Script's SendRequest Body

Hi all, not sure this is a Just Getting Started, but it is one of the first questions I have had that wasn’t pretty easily solved with a Google search.

I have an API call that returns an array object that I loop thru and pull out one piece of information that I need to pass into a subsequent POST request call. However, I cannot seem to figure out how to get that variable’s value correctly inserted into the Body I use on my post. Any assistance would be great! Thank you everyone!

You just call it by its variable name.

"ItemId": wltemid
1 Like

You know… magic kinda loses its sparkle… its mysteriousness, when it is explained. Thank you! I do now see my variable’s value inside the body. How simple!

One further question, when I send this payload on the post request, the server rejects the body as bad format and all I can see when I copy the console for this is my body missing the double quotes. Feels like I am missing something maybe fundamental here. Thanks again.

I can’t tell from the image, you need to copy and paste as text using the preformatted text option in the editor.

However, I think you have the body incorrect. This is a working example with a JSON body.

const request = {
    url: 'https://postman-echo.com/post',
    method: 'POST',
    header: {
        'Content-Type': 'application/json',
    },
    body: {
        mode: 'raw',
        raw: JSON.stringify({ 'testKey': 'testValue' })
    }
};
1 Like

Mike,

Thank you for both replies. It is working now! So much to learn!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.