# How filter item data using search api?

**URL:** <https://developer.squareup.com/forums/t/how-filter-item-data-using-search-api/19347>\
**Category:** Questions\
**Created:** [October 28, 2024, 4:40am UTC](https://developer.squareup.com/forums/t/how-filter-item-data-using-search-api/19347 "2024-10-28T04:40:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![selvaganapathi.A](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@selvaganapathi.A](https://developer.squareup.com/forums/u/selvaganapathi.A)\
**Post date:** [October 28, 2024, 4:40am UTC](https://developer.squareup.com/forums/t/how-filter-item-data-using-search-api/19347/1 "2024-10-28T04:40:27Z")

</div>

public static function catalogSyncAPI($squareAccount, $objectTypes = null, $cursor = null) {  
$squareApi = new Api($squareAccount-\>getAccessToken());

```
	$params = [
		"include_deleted_objects" => false,
		"include_related_objects" => true,
		"limit" => 50,
		"object_types" => $objectTypes ? [$objectTypes] : ["CATEGORY"],
	];

	if ($objectTypes === "CATEGORY" || (isset($params['object_types']) && in_array("CATEGORY", $params['object_types']))) {
		$params["query"] = [
			"prefix_query" => [
				"attribute_name" => "name",
				"attribute_prefix" => "CA "
			]
		];
	}

	if ($cursor !== null) {
		$params["cursor"] = $cursor;
	}

	$combinedDetails = $squareApi->searchSquareCatalogObjects($params);

	if ($combinedDetails['status'] === 200) {
		if (isset($combinedDetails['data'])) {
			SplunkLog('Square', "Catalog Data Fetched");
			return $combinedDetails['data'];
		} else {
			$response = $combinedDetails['error'];
			SplunkLog('Square', [
				'error' => $response['errors'][0]['detail'],
				'message' => 'Failed to fetch Square catalog'
			]);
			return null;
		}
	}
	return null;
}

```

catergories=Map:getbyObject(“CATEGORY”);

Filter Square Catalog Item using Category Ids Using Search Api

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [October 28, 2024, 4:41am UTC](https://developer.squareup.com/forums/t/how-filter-item-data-using-search-api/19347/2 "2024-10-28T04:41:12Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Search for Items and Objects](https://developer.squareup.com/docs/catalog-api/search-catalog)**
>
> Learn how to search for objects, including items or items variations, programmatically using the SearchCatalogItems and SearchCatalogObjects endpoints.

> **[Call the SearchCatalogObjects Endpoint](https://developer.squareup.com/docs/catalog-api/search-catalog-objects)**
>
> Learn how to use the SearchCatalogObjects endpoint to search for objects of any type programmatically.

> **Additional Documentation**
>
> [Catalog API](https://developer.squareup.com/docs/catalog-api/what-it-does)  
> [Retrieve Catalog Objects](https://developer.squareup.com/docs/catalog-api/retrieve-catalog-objects)  
> [Call the SearchCatalogItems Endpoint](https://developer.squareup.com/docs/catalog-api/search-catalog-items)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [October 28, 2024, 4:39pm UTC](https://developer.squareup.com/forums/t/how-filter-item-data-using-search-api/19347/3 "2024-10-28T16:39:16Z")

</div>

To filter Square Catalog Items using Category IDs, you can use the `SearchCatalogObjects` endpoint of the Catalog API. You can specify the `category_ids` filter in the query parameters to filter items by their associated category IDs.

Here is a sample request:

```json
{
  "object_types": ["ITEM"],
  "query": {
    "exact_query": {
      "attribute_name": "category_id",
      "attribute_value": "YOUR_CATEGORY_ID"
    }
  }
}

```

Replace `YOUR_CATEGORY_ID` with the ID of the category you want to filter by. This will return all items that are associated with the specified category.

If you want to filter by multiple category IDs, you can use the `or_query` filter:

```json
{
  "object_types": ["ITEM"],
  "query": {
    "or_query": {
      "filters": [
        {
          "exact_query": {
            "attribute_name": "category_id",
            "attribute_value": "CATEGORY_ID_1"
          }
        },
        {
          "exact_query": {
            "attribute_name": "category_id",
            "attribute_value": "CATEGORY_ID_2"
          }
        }
        // Add more filters as needed
      ]
    }
  }
}

```

Replace `CATEGORY_ID_1` and `CATEGORY_ID_2` with the IDs of the categories you want to filter by. This will return all items that are associated with any of the specified categories.

_This answer was reviewed by @Bryan-Square._
