Home > OS >  response.map is not a function
response.map is not a function

Time:01-26

I'm trying to loop a request to extract the ID's from a previous request. I followed the steps in this video https://www.youtube.com/watch?v=4wuvgX-egdc but i can't get it to work. As I see it the problem is that {} is not an array but I would like to search within "campaigns" which seems to be an array. (As you probably understand I'm new to this)

Here's the request I've sent and would like to loop through to extract the ID's that I wish to use in the next request. (there are several hundreds of ID's)

{
    "campaigns": [
        {
            "id": 373894,
            "name": "Benriach",
            "created_at": "2022-01-21 13:37:34",
            "sent_at": "2022-01-21 13:37:53",
            "status": "sent",
            "type": "text_message"
        },

Here's the test that I'm trying to run.

const response = pm.response.json();
const campaignids = response.map (campaignid => campaigns.id);
console.log(campaignids);
pm.variables.set('campaignids', campaignids);

Here's how it looks>> Screenshot

The end goal is to use Postman to extract campaign statistics from an e-mail marketing tool and then send it on into Google Data Studio where I want to create a dashboard for e-mail-campaigns using both data from the e-mail marketing tool as well as website data.

CodePudding user response:

const campaignids = response.map (campaignid => campaigns.id); here is the problem space between map (

const response = pm.response.json();
const campaignids = response.map(campaign => campaign.id);
console.log(campaignids);
pm.variables.set('campaignids', campaignids);

and make sure response should be an array

  •  Tags:  
  • Related