Agents
Retrieve all active agents for a specific company using company ID and Cognivo code.
Endpoint
POST /api/v1/agent/get_by_company
const response = await fetch('/api/v1/agent/get_by_company', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
import requests
response = requests.post(
'https://www.cognivo.app/api/v1/agent/get_by_company',
headers={'Authorization': 'Bearer <token>'},
json=data
)
Authentication
Bearer Token RequiredThe token must be valid for agent endpoint and POST method.
Authorization: Bearer <your_token_here>
Body Parameters
Unique identifier of the company
Cognivo code of the company (must be non-empty)
Responses
{
"status": "success",
"company_id": 1,
"company_name": "Demo Company",
"cognivo_code": "COGNIVO_DEMO",
"agents": [
{
"id": 5,
"name": "Sales Agent",
"description": "Agent specialized in sales and customer service"
},
{
"id": 8,
"name": "Support Agent",
"description": "Agent for technical support and problem resolution"
}
],
"total_agents": 2
}
{
"status": "error",
"message": "Invalid Authorization header format"
}
{
"status": "error",
"message": "Fields company_id and code are required"
}
{
"status": "not found",
"message": "Company not found"
}
{
"status": "error",
"message": "Internal server error description"
}
Example 1: Get company agents
curl -X POST "https://www.cognivo.app/api/v1/agent/get_by_company" \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." \
-H "Content-Type: application/json" \
-d '{
"company_id": 1,
"code": "COGNIVO_DEMO"
}'
import requests
def get_agents_by_company():
url = "https://www.cognivo.app/api/v1/agent/get_by_company"
headers = {
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"Content-Type": "application/json"
}
data = {
"company_id": 1,
"code": "COGNIVO_DEMO"
}
response = requests.post(url, headers=headers, json=data)
return response.json()
result = get_agents_by_company()
print(f"Found {result['total_agents']} agents")
const getAgentsByCompany = async () => {
const response = await fetch('https://www.cognivo.app/api/v1/agent/get_by_company', {
method: 'POST',
headers: {
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...',
'Content-Type': 'application/json'
},
body: JSON.stringify({
company_id: 1,
code: "COGNIVO_DEMO"
})
});
const result = await response.json();
console.log(`Found ${result.total_agents} agents`);
return result;
};
Important Considerations
Validations
- Bearer token must be valid and properly formatted
- company_id must be a valid integer
- code must be a non-empty string
- Company must exist with provided ID and code
Behavior
- Returns only active agents
- Agent descriptions are HTML cleaned
- Results are filtered by company ownership
- Empty results return valid response with 0 agents
Limits
- Fast lookup using indexed company fields
- Efficient agent filtering by active status
- No specific limit on number of agents returned
Troubleshooting
Error: "Company not found"
Solution: Contact your system administrator to verify the company ID and code combination.
Error: "Fields company_id and code are required"
Solution: Ensure both company_id and code are included in the request body.
Solution: This is normal if the company has no active agents. Contact your system administrator to verify agent status.
Version: 1.0
Last updated: 2025-01-13