> ## 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.

# Create Saved Search

> Create a new saved search

## Path Parameters

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

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

## Request Body

<ParamField body="name" type="string" required>
  Display name for the saved search
</ParamField>

<ParamField body="type" type="string" required>
  Search type: `content` or `asset`
</ParamField>

<ParamField body="description" type="string">
  Optional description
</ParamField>

<ParamField body="folderId" type="string">
  Parent folder ID (omit for root level). The folder must exist.
</ParamField>

<ParamField body="filter" type="object" required>
  Search filter criteria using standard filter operators
</ParamField>

<ParamField body="sort" type="object[]" required>
  Sort criteria array
</ParamField>

### Example Request

```json theme={null}
{
  "name": "Recent Images",
  "description": "Recently uploaded image assets",
  "type": "asset",
  "filter": {
    "type": {
      "in": ["image/jpeg", "image/png"]
    },
    "updatedAt": {
      "gte": "2024-03-01T00:00:00Z"
    }
  },
  "sort": [
    { "field": "createdAt", "order": "desc" }
  ]
}
```

## Response

Returns the created SavedSearch object.

```json theme={null}
{
  "data": {
    "id": "ss789",
    "name": "Recent Images",
    "description": "Recently uploaded image assets",
    "type": "asset",
    "filter": {
      "type": {
        "in": ["image/jpeg", "image/png"]
      },
      "updatedAt": {
        "gte": "2024-03-01T00:00:00Z"
      }
    },
    "sort": [
      { "field": "createdAt", "order": "desc" }
    ],
    "favorites": [],
    "metadata": {
      "useCount": 0
    },
    "createdAt": "2024-03-22T10:00:00Z",
    "updatedAt": "2024-03-22T10:00:00Z"
  }
}
```

## Error Responses

### Folder Not Found

```json theme={null}
{
  "error": {
    "code": "FOLDER_NOT_FOUND",
    "message": "Folder with ID \"folder123\" not found"
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Recent Images",
      "type": "asset",
      "filter": {
        "type": { "in": ["image/jpeg", "image/png"] }
      },
      "sort": [{ "field": "createdAt", "order": "desc" }]
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: 'Recent Images',
        type: 'asset',
        filter: {
          type: { in: ['image/jpeg', 'image/png'] }
        },
        sort: [{ field: 'createdAt', order: 'desc' }]
      })
    }
  );

  const { data: savedSearch } = await response.json();
  console.log(`Created saved search: ${savedSearch.id}`);
  ```

  ```swift Swift theme={null}
  struct CreateSavedSearchRequest: Encodable {
      let name: String
      let type: String
      let filter: [String: [String: Any]]
      let sort: [[String: String]]
  }

  let request = CreateSavedSearchRequest(
      name: "Recent Images",
      type: "asset",
      filter: ["type": ["in": ["image/jpeg", "image/png"]]],
      sort: [["field": "createdAt", "order": "desc"]]
  )

  // Make POST request with encoded body
  ```

  ```kotlin Kotlin theme={null}
  val response = client.post("https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches") {
      header("Authorization", "Bearer YOUR_JWT")
      contentType(ContentType.Application.Json)
      setBody(CreateSavedSearchRequest(
          name = "Recent Images",
          type = "asset",
          filter = mapOf("type" to mapOf("in" to listOf("image/jpeg", "image/png"))),
          sort = listOf(mapOf("field" to "createdAt", "order" to "desc"))
      ))
  }
  ```
</CodeGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.