> ## Documentation Index
> Fetch the complete documentation index at: https://docs.metabind.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Advanced Filtering

> Complex asset queries using filter operators

For complex queries, use the POST method with a JSON request body that provides greater expressiveness than query parameters.

## Path Parameters

<ParamField path="organizationId" type="string" required>
  Organization ID
</ParamField>

<ParamField path="projectId" type="string" required>
  Project ID
</ParamField>

## Request Body

<ParamField body="filter" type="object">
  Filter conditions using operators
</ParamField>

<ParamField body="sort" type="array">
  Array of sort objects with `field` and `order`
</ParamField>

<ParamField body="lastKey" type="string">
  Pagination cursor from previous response
</ParamField>

<ParamField body="limit" type="number" default="10">
  Items per page (default: 10)
</ParamField>

### Example Request

```json theme={null}
{
  "filter": {
    "type": {
      "in": ["image/jpeg", "image/png"]
    },
    "tags": {
      "any": ["hero", "product"]
    },
    "status": {
      "eq": "active"
    },
    "updatedAt": {
      "gte": "2024-01-01T00:00:00Z",
      "lte": "2024-12-31T23:59:59Z"
    }
  },
  "sort": [
    { "field": "updatedAt", "order": "desc" }
  ],
  "limit": 10
}
```

## Response

Returns paginated asset results matching the filter criteria.

```json theme={null}
{
  "data": [
    {
      "id": "asset123",
      "name": "hero-image.jpg",
      "type": "image/jpeg",
      "size": 245760,
      "status": "active",
      "tags": ["hero", "homepage"],
      "createdAt": "2024-03-20T10:00:00Z",
      "updatedAt": "2024-03-20T10:00:00Z"
    }
  ],
  "pagination": {
    "lastKey": "eyJwayI6Ik9SR..."
  }
}
```

## Combined Approach

You can combine query parameters with a request body. Body filters take precedence when there are conflicts.

```bash theme={null}
POST /app/v1/organizations/:organizationId/projects/:projectId/assets/search?status=active&sort=createdAt:desc
```

```json theme={null}
{
  "filter": {
    "type": {
      "in": ["image/jpeg", "image/png"]
    },
    "tags": {
      "any": ["hero", "product"]
    }
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/assets/search" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "filter": {
        "type": { "like": "image/%" },
        "status": { "eq": "active" }
      },
      "sort": [{ "field": "updatedAt", "order": "desc" }],
      "limit": 50
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/assets/search',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        filter: {
          type: { like: 'image/%' },
          status: { eq: 'active' }
        },
        sort: [{ field: 'updatedAt', order: 'desc' }],
        limit: 50
      })
    }
  );

  const { data: assets, pagination } = await response.json();
  console.log(`Found ${assets.length} matching assets`);
  ```
</CodeGroup>
