# Search Agents

GET https://services.leadconnectorhq.com/conversation-ai/agents/search

Searches for AI agents based on various criteria including name, status, and configuration. Supports advanced filtering and full-text search capabilities.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `conversation-ai.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `startAfter` | string | No | Start after is the agent id to start after, Serving as skip, send empty when first page |
| `limit` | number | No | Records per page |
| `query` | string | No | query to search on agent name, must be provided in lowercase |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/conversation-ai/agents/search": {
      "get": {
        "summary": "Search Agents",
        "operationId": "searchAgents",
        "description": "Searches for AI agents based on various criteria including name, status, and configuration. Supports advanced filtering and full-text search capabilities.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "startAfter",
            "required": false,
            "in": "query",
            "description": "Start after is the agent id to start after, Serving as skip, send empty when first page",
            "schema": {
              "example": "Exampleee123",
              "type": "string"
            }
          },
          {
            "name": "limit",
            "required": false,
            "in": "query",
            "description": "Records per page",
            "schema": {
              "example": 1,
              "type": "number"
            }
          },
          {
            "name": "query",
            "required": false,
            "in": "query",
            "description": "query to search on agent name, must be provided in lowercase",
            "schema": {
              "example": "booking",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchEmployeeResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "conversation-ai.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "SearchEmployeeResponseDTO": {
        "type": "object",
        "properties": {
          "agents": {
            "description": "List of agents matching the search criteria.",
            "example": [
              {
                "id": "emp_123",
                "name": "John Doe",
                "mode": "auto-pilot",
                "channels": [
                  "SMS"
                ],
                "waitTime": 30,
                "waitTimeUnit": "seconds",
                "sleepEnabled": false,
                "actions": [],
                "isPrimary": false,
                "autoPilotMaxMessages": 25
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "example": "emp_123",
                  "description": "Unique identifier for the agent."
                },
                "name": {
                  "type": "string",
                  "example": "John Doe",
                  "description": "Name of the agent."
                },
                "businessName": {
                  "type": "string",
                  "example": "Tech Corp",
                  "description": "Name of the business the agent represents."
                },
                "mode": {
                  "type": "string",
                  "enum": [
                    "off",
                    "suggestive",
                    "auto-pilot"
                  ],
                  "example": "auto-pilot",
                  "description": "Current operating mode of the agent."
                },
                "channels": {
                  "example": [
                    "SMS",
                    "Live_Chat"
                  ],
                  "description": "Communication channels the agent operates on.",
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "waitTime": {
                  "type": "number",
                  "example": 30,
                  "description": "Wait time before agent responds."
                },
                "waitTimeUnit": {
                  "type": "string",
                  "enum": [
                    "minutes",
                    "seconds"
                  ],
                  "example": "seconds",
                  "description": "Unit for wait time."
                },
                "sleepEnabled": {
                  "type": "boolean",
                  "example": false,
                  "description": "Indicates if sleep functionality is enabled.",
                  "deprecated": true
                },
                "sleepOnManualMessage": {
                  "type": "boolean",
                  "example": false,
                  "description": "Whether the bot sleeps on manual outbound messages."
                },
                "sleepOnWorkflowMessage": {
                  "type": "boolean",
                  "example": false,
                  "description": "Whether the bot sleeps on workflow outbound messages."
                },
                "sleepTime": {
                  "type": "number",
                  "example": 2,
                  "description": "Duration of sleep period."
                },
                "sleepTimeUnit": {
                  "type": "string",
                  "enum": [
                    "hours",
                    "minutes",
                    "seconds"
                  ],
                  "example": "hours",
                  "description": "Unit of sleep time."
                },
                "actions": {
                  "example": [
                    {
                      "id": "action_123",
                      "type": "triggerWorkflow"
                    }
                  ],
                  "description": "List of actions associated with this agent.",
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                },
                "isPrimary": {
                  "type": "boolean",
                  "example": false,
                  "description": "Indicates if this agent is a primary agent. (First agent created for a location is primary by default)"
                },
                "autoPilotMaxMessages": {
                  "type": "number",
                  "example": 25,
                  "description": "Maximum number of messages in auto-pilot mode before requiring human intervention."
                },
                "goal": {
                  "type": "object",
                  "example": {
                    "prompt": "Assist customers",
                    "type": "custom",
                    "actionId": null
                  },
                  "description": "Goal configuration for the agent."
                },
                "knowledgeBaseIds": {
                  "example": [
                    "kb_123",
                    "kb_456"
                  ],
                  "description": "Array of knowledge base IDs associated with this agent.",
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "createdAt": {
                  "type": "string",
                  "example": "2024-01-01T00:00:00Z",
                  "description": "Timestamp when the agent was created."
                },
                "updatedAt": {
                  "type": "string",
                  "example": "2024-01-01T00:00:00Z",
                  "description": "Timestamp when the agent was last updated."
                }
              },
              "required": [
                "id",
                "name",
                "mode",
                "channels",
                "waitTime",
                "waitTimeUnit",
                "sleepEnabled",
                "actions",
                "isPrimary",
                "autoPilotMaxMessages",
                "createdAt",
                "updatedAt"
              ],
              "title": "EmployeeListItemDTO"
            }
          },
          "totalCount": {
            "type": "number",
            "example": 100,
            "description": "Total number of agents in the location (unfiltered count)."
          },
          "count": {
            "type": "number",
            "example": 25,
            "description": "Number of agents in the current response (filtered/paginated count)."
          }
        },
        "required": [
          "agents",
          "totalCount",
          "count"
        ],
        "title": "SearchEmployeeResponseDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/conversation-ai/agents/search' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/conversation-ai/agents/search', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/conversation-ai/agents/search"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

response = requests.get(url, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/conversation-ai/agents/search',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/conversation-ai/agents/search")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/conversation-ai/agents/search"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/conversation-ai/agents/search")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/conversation-ai/agents/search' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
