# How do I access query parameter values in Laminas API Tools

**URL:** <https://discourse.laminas.dev/t/how-do-i-access-query-parameter-values-in-laminas-api-tools/2790>\
**Category:** API Tools\
**Created:** [February 25, 2022, 3:14pm UTC](https://discourse.laminas.dev/t/how-do-i-access-query-parameter-values-in-laminas-api-tools/2790 "2022-02-25T15:14:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjivsharmalv](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/sanjivsharmalv/32/1164_2.png) [@sanjivsharmalv](https://discourse.laminas.dev/u/sanjivsharmalv)\
**Post date:** [February 25, 2022, 3:14pm UTC](https://discourse.laminas.dev/t/how-do-i-access-query-parameter-values-in-laminas-api-tools/2790/1 "2022-02-25T15:14:53Z")

</div>

I want to access multiple query parameters in the URL, please refer to the screenshot.  
In the corresponding resource file it gets mapped on the fetch($id) method. I can see only one parameter as expected, how do I access the other parameters as given in the screenshot GET method. If someone wants to know why do I need multiple parameters ? The answer is - these multiple parameters collectively identifies an item in the db table.

 ![Screenshot from 2022-02-25 16-52-42](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/4/489de595bec42dc5863b353dd51c6ae717bf62aa.png)

So my question is how do I specify multiple parameters and access the same in the corresponding resource file.

---

<div class="post-metadata">

**Author:** ![ezkimo](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ezkimo/32/781_2.png) [@ezkimo](https://discourse.laminas.dev/u/ezkimo)\
**Post date:** [February 28, 2022, 8:26am UTC](https://discourse.laminas.dev/t/how-do-i-access-query-parameter-values-in-laminas-api-tools/2790/2 "2022-02-28T08:26:09Z")

</div>

Good morning,

hope you 're doing well. It’s nice to see that you’re making progress with the API tools. Since resources are event driven and follow a specific pattern, it 's not a good practice to handle more than one identifier in a fetch method, which is designed to return a specific dataset. From the point of view of the consideration, in your case you rather execute a fetchAll with filter parameters.

There is a good repository to archive what you want, when you 're using doctrine orm: [GitHub - laminas-api-tools/api-tools-doctrine-querybuilder: Laminas API Tools Doctrine QueryBuilder module](https://github.com/laminas-api-tools/api-tools-doctrine-querybuilder)

You can set filter parameters with the doctrine query builder, that do exactly what you want. So you don’t have to reprogram this filter for each resource. It works directly for all resources because of the event driven system of the query builder.

Nevertheless you can archive this functionality on your own. Let us have a look at the `\Laminas\ApiTools\Rest\AbstractResourceListener.php` file in line 182 and following.

```auto
...
case 'fetchAll':
    $queryParams = $event->getQueryParams() ?: [];
    return $this->fetchAll($queryParams);
...

```

As you can see the `fetchAll` method retrieves all query params so that you can use it in your implementation. This leads us to your query. Assuming it is formed like

`test.apitools.eu/v1/categories-description?id[]=22&id[]=33`

In the given query we got two ids 22 and 33. In your resource you can access them as in the following example.

```auto
public function fetchAll($params = [])
{
    $ids = $params['id']; // array with the given id 's in the query
    ...
}

```

Of course, you can also use the query parameters in all other methods of your resource.

```auto
public function fetch($id)
{
    $queryParams = $this->event->getQueryParams() ?: [];
    
    $ids = [];
    if (isset($queryParams['id'])) {
        $ids = $queryParams['id']; // array with the given ids from the query
    } 
}

```

---

<div class="post-metadata">

**Author:** ![sanjivsharmalv](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/sanjivsharmalv/32/1164_2.png) [@sanjivsharmalv](https://discourse.laminas.dev/u/sanjivsharmalv)\
**Post date:** [February 28, 2022, 10:30am UTC](https://discourse.laminas.dev/t/how-do-i-access-query-parameter-values-in-laminas-api-tools/2790/3 "2022-02-28T10:30:15Z")

</div>

Thanks! Hope you are doing good too. That was helpful.
