Flow "Request" Block: Response Body displays sub-request

Hey! Long time watcher first time caller.

  • I created a “Get All” request to get a list of objects. In the request’s "Post-request-scripts (tests) I’m executing “Get by ID” requests.
    When executing this Request using the “Flows” feature, the response body displays one of the “Get by ID” responses instead of the “Get All” response.

  • Platform: OS X 23.5.0, 11.2.1-ui-240611-2311

  • Script:

var responseData = pm.response.json();
# Test for validating that each 'id' field in the response data is a string and exists
responseData.data.forEach(function(tag) {
  pm.test(`'id' field should exist and be a string for tag ${tag.id}`, function () {
    pm.expect(tag).to.have.property('id').that.is.a('string');
  });
});

Hi @material-operator-66

Welcome to the forums!

Can you run your request in flows with all tests and scripts disabled/removed and see if it returns just a single record instead of the expected list?

Sure! This is the same flow after I commented out all of the tests:

Hi @material-operator-66

Do you have any other tests that you’re running that could be interfering with the response? I re-constructed an API similar to yours and added in your test and the response came back with the list.

If you run with just this test enabled does the issue still happen?

Created a new flow that only executes this one request.
With Tests commented out:
image
With tests enabled:

Script:

const tagList = pm.response.json().data;

// Ensure that the response contains an array of tags
pm.test("tag list should be an array", function () {
    pm.expect(tagList).to.be.an('array');
});

// Iterate over each tag in the list
tagList.forEach(function(tag) {
    const tagId = tag.id;

    // Send a request to get the tag by ID
    pm.sendRequest({
        url: pm.environment.get('base_url') + 'tags/' + tagId,
        method: 'GET',
        header: {
            'x-api-key': `${pm.environment.get("token")}` // Add your API key here
        }
    }, function (err, res) {
        // Parse the response
        const tagDetails = res.json();

        // Run your tests on the tag details response
        pm.test(`Response status code should be 200 for tag ${tagId}`, function () {
            pm.expect(res).to.have.status(200);
        });
        });

    });
});

Tell me if I can be of any service otherwise.
If you want to video-call with screen-sharing, I’m available GMT+3 10:00-19:00 :smiley:

Hi @material-operator-66

Thank you for providing that.

The sendRequest function will override the Send Request block’s output with the last run request.

I recommend performing this test as part of the flow instead :slight_smile:

There are several ways to achieve it but here’s one implementation:

You could also use an If block to check the status after each request and log the non 200 ones if you would prefer.

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