Медиафайлы
Управление файлами
Как получать, удалять и связывать медиафайлы с external ID
После загрузки медиафайлов вы можете получать их информацию, удалять и управлять external ID.
Получите информацию о файле
По ID
const response = await fetch('https://crm.rentix.md/api/v1/media/123', {
headers: {
'Authorization': 'ApiKey YOUR_API_KEY'
}
});
const media = await response.json();
console.log(media);
curl https://crm.rentix.md/api/v1/media/123 \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/media/123');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: ApiKey YOUR_API_KEY'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$media = json_decode($response, true);
По external ID
const response = await fetch('https://crm.rentix.md/api/v1/media/external/apt-001-photo-1', {
headers: {
'Authorization': 'ApiKey YOUR_API_KEY'
}
});
const media = await response.json();
console.log(media);
curl https://crm.rentix.md/api/v1/media/external/apt-001-photo-1 \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/media/external/apt-001-photo-1');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: ApiKey YOUR_API_KEY'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$media = json_decode($response, true);
Ответ
{
"id": 123,
"externalId": "apt-001-photo-1",
"size": 245000,
"contentType": "image/jpeg",
"optimization": "success",
"blurhash": "L7HuX^zY1z-6ADx?0z2@1Io#{yV_",
"originalUrl": "https://storage.../original.jpg",
"variants": [
{ "url": "https://storage.../128.webp", "variantSize": "128", "size": 4074 },
{ "url": "https://storage.../512.webp", "variantSize": "512", "size": 32850 },
{ "url": "https://storage.../1024.webp", "variantSize": "1024", "size": 98500 }
]
}
| Поле | Описание |
|---|---|
id | Внутренний ID файла |
externalId | Ваш ID из CRM (если был указан) |
size | Размер оригинала в байтах |
contentType | MIME-тип файла |
optimization | Статус оптимизации |
blurhash | Строка для генерации плейсхолдера |
originalUrl | URL оригинального файла |
variants | Оптимизированные версии разных размеров |
Удалите файл
Удаление освобождает место и удаляет файл со всех объявлений, где он использовался.
По ID
const response = await fetch('https://crm.rentix.md/api/v1/media/123', {
method: 'DELETE',
headers: {
'Authorization': 'ApiKey YOUR_API_KEY'
}
});
const result = await response.json();
console.log(result); // { deleted: true }
curl -X DELETE https://crm.rentix.md/api/v1/media/123 \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/media/123');
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);
$result = json_decode($response, true);
Ответ
{
"deleted": true
}
По external ID
const response = await fetch('https://crm.rentix.md/api/v1/media/external/apt-001-photo-1', {
method: 'DELETE',
headers: {
'Authorization': 'ApiKey YOUR_API_KEY'
}
});
const result = await response.json();
console.log(result); // { deleted: true, mediaId: 123 }
curl -X DELETE https://crm.rentix.md/api/v1/media/external/apt-001-photo-1 \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/media/external/apt-001-photo-1');
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);
$result = json_decode($response, true);
Ответ
{
"deleted": true,
"mediaId": 123
}
Удаление необратимо. Если файл привязан к объявлениям, он будет откреплён от них.
Управление external ID
Привяжите external ID
Если файл был загружен без external ID, его можно добавить позже:
const response = await fetch('https://crm.rentix.md/api/v1/media/123/link', {
method: 'POST',
headers: {
'Authorization': 'ApiKey YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ externalId: 'apt-001-photo-1' })
});
const result = await response.json();
console.log(result); // { mediaId: 123, externalId: 'apt-001-photo-1', linked: true }
curl -X POST https://crm.rentix.md/api/v1/media/123/link \
-H "Authorization: ApiKey YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "externalId": "apt-001-photo-1" }'
$data = ['externalId' => 'apt-001-photo-1'];
$ch = curl_init('https://crm.rentix.md/api/v1/media/123/link');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: ApiKey YOUR_API_KEY',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$result = json_decode($response, true);
Ответ
{
"mediaId": 123,
"externalId": "apt-001-photo-1",
"linked": true
}
Отвяжите external ID
const response = await fetch('https://crm.rentix.md/api/v1/media/123/link', {
method: 'DELETE',
headers: {
'Authorization': 'ApiKey YOUR_API_KEY'
}
});
const result = await response.json();
console.log(result); // { mediaId: 123, externalId: 'apt-001-photo-1', unlinked: true }
curl -X DELETE https://crm.rentix.md/api/v1/media/123/link \
-H "Authorization: ApiKey YOUR_API_KEY"
$ch = curl_init('https://crm.rentix.md/api/v1/media/123/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);
$result = json_decode($response, true);
Ответ
{
"mediaId": 123,
"externalId": "apt-001-photo-1",
"unlinked": true
}
Статусы оптимизации
После загрузки файл проходит оптимизацию. Проверяйте поле optimization:
| Статус | Описание | Действие |
|---|---|---|
pending | В очереди | Подождите |
in_progress | Обрабатывается | Подождите |
success | Готово | Можно использовать |
failed | Ошибка | Загрузите другой файл |
При привязке к объявлению система автоматически ждёт завершения оптимизации.
Частые ошибки
| Ошибка | Причина | Решение |
|---|---|---|
External ID already linked | ID уже используется другим файлом | Используйте уникальный ID |
File already has external ID | У файла уже есть external ID | Сначала отвяжите текущий |
File not found | Файл не существует или принадлежит другому агентству | Проверьте ID |