Avito integration with a Laravel CRM: book listings, queues and stock synchronization

Case study · Laravel · Avito · Book e-commerce

10 daysimplementation time
$700integration cost
XML + APIpublishing and synchronization
One inventoryfour marketplaces

We connected Avito to an existing bookstore CRM in 10 days. The work cost $700.

The CRM already integrated with Ozon, Wildberries and Yandex Market. Avito was added to the existing inventory system, sharing stock levels, reservations, inventory movements, synchronization queues and a discrepancy checking page.

The main challenge was handling books available as a single copy. After an order on one marketplace, availability must decrease on the others. A repeated order import, an API delay or an old queued job must not deduct stock twice or put a sold book back on sale.

This extends the book e-commerce CRM. AI-assisted product preparation is covered in the Book Processing Pipeline article. Here, the focus is connecting another marketplace to the shared inventory.

Integration architecture

Responsibilities were split across separate services:

AvitoApiService

Authentication, HTTP requests and stock retrieval.

AvitoBookPayloadService

Preparing listing data from a book record.

AvitoPublicationService

Generating XML and starting feed uploads.

AvitoSyncService

Importing listings, publication reports and stock levels.

AvitoOrderSyncService

Retrieving orders and passing them to the shared inventory service.

AvitoStockService

Sending stock levels and checking the result.

Publishing books through an XML feed

Publishing uses Avito's XML feed upload mechanism. The CRM builds the file from its own data, requests processing through the API, retrieves a report and checks that the listing has appeared.

A permanent identifier links the records:

Id: knigolyub-book-{book_id}
AvitoId: the existing listing's identifier

This link allows listings to be updated while retaining their identifiers. Before publication, the CRM checks the book's status, available stock, physical shelf, price and availability of product photos.

Existing listings retain their current prices during updates. Changing a selected book must not rename other listings in the shared XML feed.

The file contains the full catalog of eligible listings. Sending only a few selected books instead of the complete feed could cause other listings to be removed. Books confirmed as unavailable are excluded; manually deactivated listings are protected against accidental reactivation.

Laravel queues and publishing controls

Long operations run in Laravel Queue. Separate jobs handle publishing, imports and stock updates:

Job Purpose
PublishAvitoFeedJob Automatically prepare and start publication.
PublishSelectedAvitoBooks Manually publish selected books.
SyncAvitoAccountJob Synchronize the catalog and orders.
SyncAvitoProductStockJob Set current stock after a listing is activated.
SyncMarketplaceOrderStockJob Send the calculated stock level to a marketplace.
VerifyMarketplaceOrderStockJob Verify that the stock level was actually applied.

Inventory jobs use the stock-sync queue. Jobs are dispatched after the database transaction commits, using afterCommit(): a worker must not send an external update that could subsequently be rolled back in the database.

Unique jobs use ShouldBeUnique, while critical sections use Cache::lock(). Locks restrict concurrent processing of the same account or the same product synchronization direction.

The scheduler runs imports and publication preparation every five minutes:

Schedule::command('marketplaces:sync avito')
    ->everyFiveMinutes()
    ->withoutOverlapping();

Schedule::command('avito:dispatch-publications')
    ->everyFiveMinutes()
    ->withoutOverlapping();

The Automatic book publishing flag controls the creation of new listings. It does not disable order imports or stock updates for products already published. Sending stock levels has its own permission, send_stock.

Manual publication of selected books also works when automatic publication is disabled.

Retries and duplicate upload protection

Retry behavior depends on the operation. Account synchronization, for example, has three attempts with delays. Starting a feed upload cannot simply be retried after every timeout: Avito may have accepted the first request even if the CRM did not receive a response.

A one-hour duplicate-call guard is therefore set before starting an upload. A manual job delays execution while the guard is active. The integration also checks that the Avito account is configured to use this CRM's XML feed.

APIs used by the integration

The integration uses separate endpoints for each operation:

Operation Method
Retrieve listings GET /core/v1/items
Check the feed upload profile GET /autoload/v2/profile
Start a feed upload POST /autoload/v1/upload
Retrieve the report GET /autoload/v4/uploads/current/items
Retrieve orders GET /order-management/1/orders
Send stock levels PUT /stock-management/1/stocks
Check stock levels POST /stock-management/1/info

Orders and shared inventory management

Avito orders go through the shared MarketplaceOrderInventoryService. No separate inventory was created for Avito.

Marketplace statuses are mapped to internal CRM states: awaiting confirmation, preparation, delivery, cancellation, receipt and return. An unknown status is stored separately and does not, by itself, count as a sale or return.

Orders are imported page by page for the last 90 days. Orders created before the account was connected are treated as historical records and must not change current inventory again.

Stock changes run in transactions with lockForUpdate() row locks. Inventory movements receive idempotency keys, so processing the same event again must not reserve or deduct the same copy twice.

A catalog import error does not prevent an attempt to retrieve orders. The synchronization job handles these operations separately, so a listing issue does not block new sales from being recorded.

Stock synchronization and outdated jobs

Available stock is calculated from physical quantity and reservations:

Available for dispatch = max(0, physical stock − reserved quantity)

If dispatch from the warehouse is blocked:
Available for dispatch = 0

When an order on another marketplace reserves the last copy, the shared inventory service creates a job to send zero stock to Avito.

Before sending, the integration checks the account, the link between the listing and the book, synchronization permissions and current availability. Positive stock must not be sent to an inactive or manually deactivated listing.

The inventory version, stock_version, protects against outdated jobs. Each job stores the version used to calculate its stock level. If inventory has since changed or a newer job exists, the previous job is marked superseded.

This addresses a specific scenario:

A job is queued: set stock to 1
The book is ordered: available stock becomes 0
The old job reaches the worker
The version check prevents it from sending 1

Verifying actual stock through the API

A separate verification runs after a stock update. A write response alone does not mean the quantity was actually applied.

AvitoStockService first checks the write result for the specific listing: success = true and no errors. A verification job then reads the stock level through the API again and compares it with the expected quantity.

Stock read requests are split into batches of ten listings and use strong_consistency: true.

If the API returns no row for a product, the CRM records unknown stock. It does not replace the last known quantity with zero. An empty response for one batch does not stop subsequent batches from being checked.

Avito was added to /stock-desync: the marketplace participates in comparisons between warehouse inventory and marketplace stock, as well as bulk synchronization of selected products. Unknown data is shown as a reason why verification remains incomplete.

Tests and live account checks

Integration tests covered scenarios including:

  • reimporting an order or cancellation without duplicating inventory movements;
  • manual publication with automatic publishing disabled;
  • no automatic publication after disabling the flag;
  • setting Avito stock to zero after the last copy is reserved on Ozon;
  • checking availability again before starting a feed upload;
  • keeping a deactivated listing out of the XML after another import;
  • preserving other listings' prices and titles during a selective update;
  • treating an empty stock response as an unknown state;
  • continuing order imports when catalog synchronization fails.

The related integration and inventory test run comprised 148 tests and 949 assertions. This total refers to the entire tested suite, including shared marketplace mechanisms.

Listing updates were also checked on a live account: the city was changed to Vologda for 48 active listings. The API confirmed the address and the preservation of identifiers, prices and titles. Two listings with zero stock were removed by the feed upload.

Results, timeline and cost

The work took 10 days and cost $700. This covered connecting Avito to the existing CRM architecture, publishing, queues, order processing, sending and verifying stock levels, monitoring interfaces and testing.

Frequently asked questions about Avito CRM integration

Can Avito be connected to an existing Laravel CRM?

Yes. In this project, Avito was connected to an existing CRM already integrated with Ozon, Wildberries and Yandex Market. The new integration shares inventory, reservations and stock movements; it does not create a separate inventory for Avito.

How does the CRM publish books on Avito?

The CRM generates a complete XML catalog of eligible listings, requests processing through the API and retrieves a report. Before publishing, it checks the book's status, available stock, shelf, price and photos. A permanent identifier links the listing to the book record.

What happens when the last copy is ordered on another marketplace?

The shared inventory service reserves the copy, recalculates availability and creates a job to send zero stock to Avito. A separate job then verifies actual stock through the API. The time required depends on queue processing and the marketplace response.

How are duplicate orders and outdated jobs handled?

Inventory movements receive idempotency keys, and stock changes use transactions with row locks. The stock_version value stops an outdated job from putting one copy back on sale after the book has been reserved.

Can automatic publication be disabled without stopping synchronization?

Yes. The automatic publishing flag controls new listings. Order imports and stock updates for published products work separately; stock updates have their own send_stock permission. Selected books can still be published manually when automatic publishing is off.

What if the API returns no stock level for a listing?

The CRM records an unknown state without replacing the last known quantity with zero. Other batches continue to be checked. The discrepancy page shows unknown data as a reason why verification is incomplete.

How long did this integration take, and what did it cost?

The project described here took 10 days and cost $700. This included connection to the existing CRM, XML publishing, queues, order processing, stock updates and verification, monitoring interfaces and testing. Other integrations are estimated according to scope and the condition of the CRM.

Related articles and integration development

Need to connect Avito or another marketplace to your CRM? Discuss an API integration.


Let’s discuss your project

Tell me what you would like to build. I will reply by email.

Or message me on Telegram @ifwcom