> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rek.la/llms.txt
> Use this file to discover all available pages before exploring further.

# Создание публикаций

> Создать одну или несколько публикаций. Для media_type=rich_message передайте точные blocks/is_rtl из message.rich_message и временные media_urls для встроенных медиа. Rekla сразу получает собственные Telegram file_id до сохранения публикации. Создание атомарно — если одна публикация не пройдёт валидацию, ни одна не будет создана.



## OpenAPI

````yaml /api/openapi.json post /external-api/publications
openapi: 3.0.1
info:
  title: Rekla External API
  description: API для интеграции внешних партнёров с платформой Rekla
  version: 1.0.0
servers:
  - url: https://api.rek.la
    description: Production
security: []
tags:
  - name: External API
    description: Эндпоинты для внешних партнёров
paths:
  /external-api/publications:
    post:
      tags:
        - External API
      summary: Создание публикаций
      description: >-
        Создать одну или несколько публикаций. Для media_type=rich_message
        передайте точные blocks/is_rtl из message.rich_message и временные
        media_urls для встроенных медиа. Rekla сразу получает собственные
        Telegram file_id до сохранения публикации. Создание атомарно — если одна
        публикация не пройдёт валидацию, ни одна не будет создана.
      parameters:
        - $ref: '#/components/parameters/XApiKey'
        - $ref: '#/components/parameters/XPartnerId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              minItems: 1
              items:
                $ref: '#/components/schemas/PublicationCreateRequest'
            examples:
              text:
                summary: Текстовая публикация
                value:
                  - external_id: pub-001
                    channel_id: -1001568992973
                    text: Текст публикации
                    text_len: 16
                    media_type: text
                    price: 1500
                    publish_date: '2030-03-01T12:00:00Z'
              rich_message:
                summary: Статья с фотографией и кнопкой
                value:
                  - external_id: article-001
                    channel_id: -1001568992973
                    media_type: rich_message
                    rich_message:
                      blocks:
                        - type: heading
                          text: Новая функция
                          size: 2
                        - type: paragraph
                          text: Теперь в Rekla можно публиковать Статьи.
                        - type: photo
                          photo:
                            - file_id: partner-bot-file-id
                              file_unique_id: AQAD-example-photo
                              width: 1280
                              height: 720
                          caption:
                            text: Подпись к фотографии
                      is_rtl: false
                      media_urls:
                        AQAD-example-photo: https://partner.example/media/article-photo.jpg
                    inline_buttons:
                      inline_keyboard:
                        - - text: Подробнее
                            url: https://example.com
                    price: 1500
                    publish_date: '2030-03-01T12:00:00Z'
      responses:
        '201':
          description: Публикации созданы
          content:
            application/json:
              schema:
                type: object
                properties:
                  publications:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: integer
                        external_id:
                          type: string
                      required:
                        - id
                        - external_id
                required:
                  - publications
              example:
                publications:
                  - id: 11607
                    external_id: pub-001
        '400':
          description: Структурная ошибка JSON/Pydantic или другая ошибка запроса
        '401':
          description: Ошибка аутентификации
        '403':
          description: Нет доступа к одному или нескольким каналам
        '422':
          description: Ошибка валидации входных данных или медиа Статьи
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalAPIErrorResponse'
              example:
                status_code: 422
                detail: missing_rich_media_url=AQAD-example-photo
                extra: null
components:
  parameters:
    XApiKey:
      name: X-API-Key
      in: header
      required: true
      description: API-ключ, полученный через Telegram-бота Rekla
      schema:
        type: string
      example: rekla_api:abc123...
    XPartnerId:
      name: X-Partner-Id
      in: header
      required: true
      description: Публичный идентификатор партнёра, выданный при регистрации
      schema:
        type: string
      example: 568d4f6f505e0458801cbd695d31f7af
  schemas:
    PublicationCreateRequest:
      type: object
      required:
        - external_id
        - channel_id
        - price
        - publish_date
      properties:
        external_id:
          type: string
          description: Внешний ID публикации в системе партнёра
        channel_id:
          type: integer
          description: Telegram ID канала (начинается с -100)
        payment_status:
          type: string
          enum:
            - not_paid
            - paid
            - partial_paid
            - overpaid
            - refund
            - refund_partial
          default: not_paid
          description: Статус оплаты
        text:
          type: string
          nullable: true
          description: Текст публикации
        text_len:
          type: integer
          nullable: true
          description: Длина текста
        media_type:
          type: string
          enum:
            - animation
            - audio
            - document
            - video
            - voice
            - photo
            - text
            - album
            - poll
            - video_note
            - rich_message
          default: text
          description: Тип медиа
        rich_message:
          allOf:
            - $ref: '#/components/schemas/ExternalRichMessageDTO'
          nullable: true
          description: Обязательно только при media_type=rich_message
        file_id:
          type: string
          nullable: true
          deprecated: true
          description: >-
            Не используйте file_id другого бота; для обычного медиа передавайте
            file_url
        file_url:
          type: string
          format: uri
          nullable: true
          description: >-
            HTTP(S) URL обычного медиа; Rekla сразу получит собственный Telegram
            file_id
        album:
          type: object
          nullable: true
          description: Конфигурация альбома (если media_type = album)
        poll:
          type: object
          nullable: true
          description: Параметры опроса (если media_type = poll)
        inline_buttons:
          type: object
          nullable: true
          description: Конфигурация инлайн-кнопок
        auto_delete:
          type: integer
          nullable: true
          description: Автоудаление через N минут
        with_sound_notification:
          type: boolean
          default: false
          description: Звуковое уведомление
        price:
          type: number
          description: Цена публикации
        publish_date:
          type: string
          format: date-time
          description: Дата и время публикации (ISO 8601)
        wp_preview:
          type: boolean
          default: false
          description: Предпросмотр ссылок
        allow_comments:
          type: boolean
          default: true
          description: Разрешить комментарии
        has_spoiler:
          type: boolean
          default: false
          description: Спойлер на медиа
        protect_content:
          type: boolean
          default: false
          description: Защита от копирования
        wp_preview_config:
          type: object
          nullable: true
          description: Конфигурация предпросмотра веб-страницы
        comment:
          type: string
          nullable: true
          description: Комментарий к публикации
    ExternalAPIErrorResponse:
      type: object
      required:
        - status_code
        - detail
      properties:
        status_code:
          type: integer
        detail:
          type: string
        extra:
          nullable: true
          oneOf:
            - type: object
              additionalProperties: true
            - type: array
              items: {}
    ExternalRichMessageDTO:
      type: object
      required:
        - blocks
      description: Статья в точном формате message.rich_message, полученном ботом партнёра.
      properties:
        blocks:
          type: array
          minItems: 1
          description: >-
            Блоки Telegram Rich Message. Draft-only блок thinking запрещён,
            включая вложенные контейнеры.
          items:
            $ref: '#/components/schemas/ExternalRichBlock'
        is_rtl:
          type: boolean
          nullable: true
          description: Исходное значение message.rich_message.is_rtl
        media_urls:
          type: object
          default: {}
          description: >-
            Временные HTTP(S) URL встроенных медиа, где ключ — file_unique_id из
            блока. URL с токеном Telegram-бота запрещён.
          additionalProperties:
            type: string
            format: uri
    ExternalRichBlock:
      type: object
      required:
        - type
      description: >-
        Точный объект блока, полученный от Telegram. Остальные свойства зависят
        от type.
      properties:
        type:
          type: string
          enum:
            - paragraph
            - heading
            - pre
            - footer
            - divider
            - mathematical_expression
            - anchor
            - list
            - blockquote
            - pullquote
            - collage
            - slideshow
            - table
            - details
            - map
            - animation
            - audio
            - photo
            - video
            - voice_note
      additionalProperties: true

````