Пользователи
Получение пользователей
Поиск агентов и привязка external ID
Получите список агентов вашего агентства, найдите конкретного агента или привяжите external ID для дальнейшей синхронизации.
Получите список агентов
Возвращает всех агентов вашего агентства.
const response = await fetch('https://crm.rentix.md/api/v1/users', {
headers: { 'Authorization': 'ApiKey YOUR_API_KEY' }
});
const { items } = await response.json();
// Найти агентов без external ID (для начальной привязки)
const unlinked = items.filter(user => !user.externalId);
console.log(`Агентов без external ID: ${unlinked.length}`);
curl https://crm.rentix.md/api/v1/users \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/users');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: ApiKey YOUR_API_KEY']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$data = json_decode($response, true);
foreach ($data['items'] as $user) {
echo $user['name'] . ' - ' . ($user['externalId'] ?? 'нет external ID') . "\n";
}
Ответ
{
"items": [
{
"id": 1,
"externalId": "agent-001",
"name": "Иван Петров",
"phone": "+373 22 123 456",
"avatar": {
"id": 123,
"contentType": "image/jpeg",
"variants": [
{ "url": "https://storage.../avatar_128.webp", "variantSize": "128" }
]
},
"description": "Опытный агент по жилой недвижимости...",
"instagram": "https://instagram.com/ivan.petrov",
"youtube": null,
"tiktok": null,
"settings": {
"posting_type": "agent",
"contact_phone": true,
"contact_whatsapp": true,
"contact_viber": false,
"contact_telegram": true
}
}
]
}
Найдите агента по ID
Используйте внутренний ID Rentix.
const response = await fetch('https://crm.rentix.md/api/v1/users/1', {
headers: { 'Authorization': 'ApiKey YOUR_API_KEY' }
});
const user = await response.json();
curl https://crm.rentix.md/api/v1/users/1 \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/users/1');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: ApiKey YOUR_API_KEY']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$user = json_decode($response, true);
Найдите агента по external ID
Используйте ID из вашей CRM.
const response = await fetch('https://crm.rentix.md/api/v1/users/external/agent-001', {
headers: { 'Authorization': 'ApiKey YOUR_API_KEY' }
});
const user = await response.json();
curl https://crm.rentix.md/api/v1/users/external/agent-001 \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/users/external/agent-001');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: ApiKey YOUR_API_KEY']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$user = json_decode($response, true);
Привяжите external ID
Связывает агента Rentix с записью в вашей CRM. После привязки можно использовать external ID для обновления профиля и привязки к объявлениям.
const response = await fetch('https://crm.rentix.md/api/v1/users/1/link', {
method: 'POST',
headers: {
'Authorization': 'ApiKey YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ externalId: 'agent-001' })
});
const result = await response.json();
console.log(`Агент ${result.id} привязан к external ID: ${result.externalId}`);
curl -X POST https://crm.rentix.md/api/v1/users/1/link \
-H "Authorization: ApiKey YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "externalId": "agent-001" }'
$ch = curl_init('https://crm.rentix.md/api/v1/users/1/link');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['externalId' => 'agent-001']));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: ApiKey YOUR_API_KEY',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
Ответ
{
"id": 1,
"externalId": "agent-001",
"linked": true
}
Отвяжите external ID
Удаляет связь между агентом Rentix и external ID.
const response = await fetch('https://crm.rentix.md/api/v1/users/1/link', {
method: 'DELETE',
headers: { 'Authorization': 'ApiKey YOUR_API_KEY' }
});
curl -X DELETE https://crm.rentix.md/api/v1/users/1/link \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/users/1/link');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: ApiKey YOUR_API_KEY']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
Ответ
{
"id": 1,
"externalId": "agent-001",
"unlinked": true
}
Сценарий: первоначальная привязка
При интеграции CRM нужно связать существующих агентов Rentix с записями в вашей системе.
Node.js
// 1. Получить всех агентов из Rentix
const response = await fetch('https://crm.rentix.md/api/v1/users', {
headers: { 'Authorization': 'ApiKey YOUR_API_KEY' }
});
const { items: rentixAgents } = await response.json();
// 2. Для каждого агента найти соответствие в CRM (например, по имени или телефону)
for (const agent of rentixAgents) {
const crmRecord = await findInCrm(agent.phone); // ваша функция поиска
if (crmRecord && !agent.externalId) {
// 3. Привязать external ID
await fetch(`https://crm.rentix.md/api/v1/users/${agent.id}/link`, {
method: 'POST',
headers: {
'Authorization': 'ApiKey YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ externalId: crmRecord.id })
});
console.log(`Привязан: ${agent.name} → ${crmRecord.id}`);
}
}
Частые ошибки
| Ошибка | Причина | Решение |
|---|---|---|
User not found | Агент не существует или не в вашем агентстве | Проверьте ID агента |
External ID already linked | Этот external ID уже у другого агента | Используйте уникальный ID для каждого агента |
User already has external ID | У агента уже есть external ID | Сначала отвяжите текущий ID |