GET Multiple Records from one API then POST to Another

Hi there,

I’m definitely a beginner when it comes to using APIs/JSON/Postman, so any help is appreciated. Thanks in advance!

I have a project where I need to GET data from a site using one API then POST that data into a different site using their API. Eventually, this needs to be an automated process that runs daily.

My initial thought was to GET the data from the first site and store those records (returns multiple) into an Array in order to POST it through the other API. I’ve been able to GET and store the data that way, but now I’m having trouble understanding how to pass the Array values into the POST Request raw body content.

Here’s how I made the Variables with stored Arrays:

const response = pm.response.json();

let jsonData = pm.response.json()

let siteID = ,
mcf = ,
pdate =
;

_.each(jsonData.records, (result) => {
siteID.push(result.fields.SiteID),
mcf.push(result.fields.MCF),
pdate.push(result.fields.Date)
})

pm.globals.set(‘siteID’, JSON.stringify(siteID))
pm.globals.set(‘mcf’, JSON.stringify(mcf))
pm.globals.set(‘pdate’, JSON.stringify(pdate))
;

console.log(response);

(For my two records, this returned values for both the 0th and 1st index; this part seems to be working.)

I can’t for the life of me figure out how to create a POST request that sends the stored array values in the raw body content. I can send a variable (using “{{variable_name}}”), but not an Array index value. I know this isn’t the correct syntax, but I thought it would be similar to this idea:

{
“DataList”: [
{
“SiteId”: “{{siteID[0]}}”, //Reference to 0th Index Value for the “siteID” Array Variable
“Meter1”: “{{mcf[0]}}”, //Reference to 0th Index Value for the “mcf” Array Variable
“DateAndTime”: “{{pdate[0]}}”, //Reference to 0th Index Value for the “pdate” Array Variable
“UserName”: “user1”,
“Notes”: “”,
“LastModifiedBy”: “”
}
]
}

I’ve tried a number of different things, but none of them successful so far. I also need to be able to iterate through the number of records in order to send multiple POSTs with the one request (probably using a for(let i = 0; i < [number of records]…)).

Please let me know if more details are needed in order to help (or if it makes sense to do this a totally different way). This is a great community and resource; there’s no way I could’ve gotten anywhere so far with everyone’s expertise, so thanks.