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

# Execute Saved Search

> Execute a saved search and return matching results

Executes a saved search using its stored filter and sort criteria, returning matching content or assets based on the search type.

## Path Parameters

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

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

<ParamField path="id" type="string" required>
  Saved search ID
</ParamField>

## Query Parameters

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

<ParamField query="lastKey" type="string">
  Cursor for pagination (from previous response)
</ParamField>

## Execution Behavior

When executing a saved search:

1. The saved search's `filter` and `sort` parameters are applied
2. The `type` field determines whether the search targets content or assets
3. Additional query parameters in the execute request are merged with the saved filter
4. Results are paginated according to the page and limit parameters
5. The search's `metadata.lastUsed` and `metadata.useCount` are updated

## Response (Content Type)

When the saved search type is `content`:

```json theme={null}
{
  "data": [
    {
      "id": "cont123",
      "name": "Getting Started with Metabind",
      "typeId": "article",
      "status": "draft",
      "createdAt": "2024-03-20T10:00:00Z",
      "updatedAt": "2024-03-21T15:30:00Z"
    }
  ],
  "pagination": {
    "lastKey": "eyJpZCI6ImNvbnQxMjMifQ=="
  },
  "searchInfo": {
    "id": "ss123",
    "name": "Draft Articles",
    "type": "content",
    "executedAt": "2024-03-22T10:00:00Z"
  }
}
```

## Response (Asset Type)

When the saved search type is `asset`:

```json theme={null}
{
  "data": [
    {
      "id": "asset123",
      "name": "hero-image.jpg",
      "type": "image/jpeg",
      "size": 245760,
      "createdAt": "2024-03-20T10:00:00Z",
      "updatedAt": "2024-03-21T15:30:00Z"
    }
  ],
  "pagination": {
    "lastKey": "eyJpZCI6ImFzc2V0MTIzIn0="
  },
  "searchInfo": {
    "id": "ss124",
    "name": "Recent Images",
    "type": "asset",
    "executedAt": "2024-03-22T10:00:00Z"
  }
}
```

## Error Responses

### Saved Search Not Found

```json theme={null}
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Saved search not found"
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches/ss123/execute?limit=10" \
    -H "Authorization: Bearer YOUR_JWT"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches/ss123/execute?limit=10',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT'
      }
    }
  );

  const { data, pagination, searchInfo } = await response.json();
  console.log(`Found ${data.length} results for "${searchInfo.name}"`);
  ```

  ```swift Swift theme={null}
  var request = URLRequest(url: URL(string: "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches/ss123/execute?limit=10")!)
  request.httpMethod = "POST"
  request.setValue("Bearer YOUR_JWT", forHTTPHeaderField: "Authorization")

  let (data, _) = try await URLSession.shared.data(for: request)
  let result = try JSONDecoder().decode(SearchExecutionResponse.self, from: data)
  print("Found \(result.data.count) results")
  ```

  ```kotlin Kotlin theme={null}
  val response = client.post("https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/saved-searches/ss123/execute") {
      header("Authorization", "Bearer YOUR_JWT")
      parameter("limit", 10)
  }

  val result = response.body<SearchExecutionResponse>()
  println("Found ${result.data.size} results for ${result.searchInfo.name}")
  ```
</CodeGroup>
