createAgent method
Implementation
Future<String> createAgent(Agent agent, String connectorName) async {
final response = await http.post(
Uri.parse('$baseUrl/deployZohoAgent?workspaceId=$workspaceId&connectorName=${connectorName}'),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
},
body: json.encode({
'name': agent.name,
'description': agent.description,
'type': 'Sales',
'image': agent.agentConfigs?.image,
'display_name': agent.agentConfigs?.displayName,
'colors': agent.agentConfigs?.colors ?? {},
}),
);
if (response.statusCode == 200 || response.statusCode == 201) {
final Map<String, dynamic> data = json.decode(response.body);
return data['agentId'];
} else {
print('Error status code: ${response.statusCode}');
print('Error response body: ${response.body}');
throw Exception('Failed to create agent');
}
}