Skip to main content

Request Parameter Collections

Working with API Operations that have a large parameter list can be messy. Grouping the parameters of such Endpoints into a single structured collection such as a data model, map or dictionary can make the code cleaner and easier to read. APIMatic allows users to apply this approach to their SDKs, either globally or to specific Operations.

Creating Request Parameter Collections

To enable this feature globally for the entire SDK, set the collectParameters CodeGen setting to true. You can also configure it at the operation level by setting the collectParameters option under the x-operation-settings OpenAPI Extension as demonstrated below:

openapi: 3.0.3
info:
title: Product Management API
description: API for managing products in an inventory system.
version: 1.0.0
paths:
/products/filter:
get:
summary: Retrieve filtered products
x-operation-settings:
collectParameters: true
parameters:
- name: category
in: query
description: Product category to filter by
required: true
schema:
type: string
example: "Electronics"
- name: price
in: query
description: Range of product prices
required: true
schema:
type: string
example: "100-500"

In this example, the /products/filter operation uses the Collect Parameters feature, which groups the category and priceRange parameters into a single collection for easier use.

SDK Usage Examples

const apiController = new ApiController(client);

// Using a single collection for parameters in TypeScript
const collect = {
category: 'Electronics',
price: '100-500'
}

await apiController.getFilteredProducts(collect)