Hi everyone,
I have question about chaining requests. My goal is to modify by API a list of repository (with a PATCH request) but I am getting this list by an other API request (with a GET request).
I made the fisrt GET request with success to get list of my repository and have a response like this :
{
“repositories”: [
{
“id”: “32191961-73f1-498e-a988-66dae2ddd8e5”,
“namespace”: “namespace1”,
“namespaceType”: “organization”,
“name”: “repo1”,
“shortDescription”: “”,
“visibility”: “public”,
“scanOnPush”: true,
“immutableTags”: false,
“enableManifestLists”: false,
“pulls”: 361,
“pushes”: 264,
“tagLimit”: 0
},
{
“id”: “58668dc9-da9e-44b8-a113-13e94007a209”,
“namespace”: “namespace1”,
“namespaceType”: “organization”,
“name”: “repo2”,
“shortDescription”: “”,
“visibility”: “priivate”,
“scanOnPush”: false,
“immutableTags”: false,
“enableManifestLists”: false,
“pulls”: 0,
“pushes”: 268,
“tagLimit”: 0
},
But I don’t find a way to launch back my request for each values of the repositories array gotten in response.
The solution I found but I think is not very elegant is :
To push in a array all the repo name I want to change and create a CSV and use it as the data file of my collection runner. What is not OK for me is that I need to edit manually the text to create the CSV file so I cannot automate the modification
Is there a proper way to do this in postman ?
This is the code that I put in the GET request to create my environment variable :
var jsonData = JSON.parse(responseBody);
var repo2change = [];
jsonData.repositories.forEach(function(repo) {
if (repo.visibility != “public”) {
repo2change.push(repo.name);
}
});
pm.environment.set(“repo2change”, JSON.stringify(repo2change, null, 2));
Best regards,
Guillaume MARTIN