# HELP | Regarding pm.sendRequest() and pm.request.url.addQueryParams()

**URL:** <https://community.postman.com/t/help-regarding-pm-sendrequest-and-pm-request-url-addqueryparams/13363>\
**Category:** Help Hub\
**Tags:** pmsendrequest, pre-request-script\
**Created:** [June 12, 2020, 6:59pm UTC](https://community.postman.com/t/help-regarding-pm-sendrequest-and-pm-request-url-addqueryparams/13363 "2020-06-12T18:59:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![qaschool](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/qaschool/32/4708_2.png) [@qaschool](https://community.postman.com/u/qaschool)\
**Post date:** [June 12, 2020, 6:59pm UTC](https://community.postman.com/t/help-regarding-pm-sendrequest-and-pm-request-url-addqueryparams/13363/1 "2020-06-12T18:59:17Z")

</div>

Hi everyone!

I would like to know if there is a solution to my problem, let me explain it:

I am using the **pm.sendRequest** and I would like to send _ **params** _ that are stored in an array called **_ids_**. But I did not find throughout the web how to accomplish that. I tried another way and it is working but not as desired, have a look:

> This code works but send multiple DELETE requests
> 
> > First it retrieves all course ID and stores them in an array. After that, for each course ID, it sends multiple DELETE requests.

```auto
const URL = pm.environment.get('base_url'), TOKEN = pm.environment.get('admin_token');

// Get All Courses
pm.sendRequest({
    url: `${URL}/content-manager/explorer/application::course.course`,
    method: 'GET',
    header: {
        'Authorization': `Bearer ${TOKEN}`
    }
}, function(err, res){
    let response = res.json(), ids = _.map(response, ({ id }) => ( id ));

    // Delete Courses
    if (typeof ids !== 'undefined' && ids.length > 0) {
        _.forEach(ids, (id, index) => {
            pm.sendRequest({
                url: `${URL}/content-manager/explorer/deleteAll/application::course.course?${index++}=${id}`,
                method: 'DELETE',
                header: {
                    'Authorization': `Bearer ${TOKEN}`
                }
            }, function(err, res){
                pm.test('Code is 200'), function() {
                    pm.expect(responseBody.code).to.be.equal(200);
                }
            });
        });
    }
});

```

As you could see, I am looping through each ID and sending a DELETE request. But I can send multiple params in just one request, like `...course.course?0=id1&1=id2&...`. For this, I can use the following code in one request:

> This code is placed in the Postman Pre-request Script

 ![Postman Delete Request](https://us1.discourse-cdn.com/getpostman/original/3X/f/b/fb8927476234265e3738fae49e343054a69459f6.png)

> Backing up the code in case image fails

```auto
const URL = pm.environment.get('base_url'), TOKEN = pm.environment.get('admin_token');

// Get All Courses
result = pm.sendRequest({
    url: `${URL}/content-manager/explorer/application::course.course`,
    method: 'GET',
    header: {
        'Authorization': `Bearer ${TOKEN}`
    }
}, function(err, res){
    let response = res.json(), ids = _.map(response, ({ id }) => ( id ));
    _.forEach(ids, (id, index) => {
        pm.request.url.addQueryParams(`${index++}=${id}`);
    });
});

```

### Question

How can I move the following block to the first example to make just one DELETE request? I mean, I want to use an alternative to `pm.request.url.addQueryParams()` to the `pm.sendRequest()` within it.

```auto
_.forEach(ids, (id, index) => {
    pm.request.url.addQueryParams(`${index++}=${id}`);
});

```

By the way, the array structure is simple: [1, 2, 3, …], the index is autogenerated by the loop.
