I want to create a script that gets the response from a youtube api request, take a field from that response and make a new POST request to another API, eg:
I think you can do this with the help of the test scripts in Postman and the feature called pm.sendRequest in the Tests script tab in the app.
What you have to do is use the below script and craft it according to your requirement and then make the custom request based on the response of the initial GET request.
Sample code to refer:
const videoId = _.get(pm.response.json(), 'path.to.video.id'),
customRequest = {
url: `https://mycustomapi.com/vid=${videoId}`,
method: 'POST',
header: {
'Accept': 'application / json',
'Content - Type': 'application / x - www - form - urlencoded'
},
body: {
mode: 'urlencoded',
urlencoded: [
{
key: "grant_type",
value: "urn:ibm:params:oauth:grant-type:iam-auth"
}
]
}
};
pm.sendRequest(customRequest, function (err, res) {
// handle the response or the error, you can even add more test cases based on this current response
});