Refactoring Postman collection to execute a collection/request from another request Pre-script

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
I have a Postman collection running with No issues, However, I am attempting to refactor it for improved reusability. In light of this, I am seeking advice on the optimal approach.

My particular use case involves two collections. The first, Connector, contains two requests - Delete Connector (Method: DELETE) and Create New Connector (Method: POST). The second collection, API E2E flow, has two requests - GET call and POST call, with the latter being dependent on the successful execution of requests 1.1 and 1.2 in the Connector collection.

In order to streamline my testing process, I am seeking advice on the most efficient method to execute requests 1.1 and 1.2 as pre-script from 2nd collection.

One approach I have tried is but didn’t like that much"…"

— PRE-SCRIPT
pm.sendRequest({
url: ‘https://api.getpostman.com/collections/21abd494-403e-486d-9b41-4f68837218d3’,
header: {
‘X-Api-Key’: '*** KEY ',
‘Content-Type’: ‘application/json’
},
body: {
mode: ‘raw’,
raw: JSON.stringify({
“collection”: {
“info”: {
“_postman_id”: “21abd494-403e-486d-9b41-4f68837218d3”
}
},
“environment”: {
“values”: []
}
})
}
}, function (err, res) {
if (err) {
console.error(err);
} else {
console.log(“RESPONSE is :” +res.text());
var runUrl = ’
Delete Connector (Method: DELETE) *** ';
pm.sendRequest({
url: runUrl,
method: ‘DELETE’,
header: {
‘X-Api-Key’: ‘*** KEY ***’
}
}, function (err, res) {
if (err) {
console.error(err);
} else {
console.log(res.text());
}
});
}
});

Also I noticed that when I am able to get collection details by hitting

https://api.getpostman.com/collections/{{collection_uid}}?apikey=*** and got response that has multiple request details

And using the response when I am trying to hit another API to get more detail of request, I am getting error message like

GET https://api.getpostman.com/collections/{{collection_uid}}/items/{{request_uid}}?apikey=***

{
“error”: {
“name”: “notFound”,
“message”: “Requested resource not found”
}
}

I think I am passing valid request_uid only but just to double check, How do we get the request_uid of the request? I am attaching ss here, can anyone confirm?

Screen Shot 2023-04-11 at 12.28.46 AM