# Automation batch script

**URL:** <https://community.postman.com/t/automation-batch-script/8461>\
**Category:** Help Hub\
**Tags:** scripts\
**Created:** [October 19, 2019, 7:12pm UTC](https://community.postman.com/t/automation-batch-script/8461 "2019-10-19T19:12:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![diplatis](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@diplatis](https://community.postman.com/u/diplatis)\
**Post date:** [October 19, 2019, 7:12pm UTC](https://community.postman.com/t/automation-batch-script/8461/1 "2019-10-19T19:12:56Z")

</div>

Hi,

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:

1. GET [https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNELID}&eventType=live&type=video&key={APIKEY}](https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=%7BCHANNELID%7D&eventType=live&type=video&key=%7BAPIKEY%7D)
2. Copy [items[id[videoId]]] from GET response
3. POST [https://mycustomapi.com/vid={VIDEOIDFROMABOVE}](https://mycustomapi.com/vid=%7BVIDEOIDFROMABOVE%7D)

Can this be done with Postman?  
Thanks!

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [October 19, 2019, 9:09pm UTC](https://community.postman.com/t/automation-batch-script/8461/2 "2019-10-19T21:09:37Z")

</div>

Hi @diplatis, welcome to the community! 👋

I think you can do this with the help of the `test` scripts in Postman and the feature called [`pm.sendRequest`](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/#pmsendrequest) 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:

```auto
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
});

```
