Base URL
https://www.agility.bg/api/v1Endpoint
POST /orders/importLimit
500 orders/request
Общ преглед
Как работи
1. Създавате ключ
Ключът е вързан към конкретен магазин и приема данни само за него.
2. Изпращате поръчки
Външната система прави POST към /orders/import с масив `orders` (до 500).
3. Поръчките са в Agility
Поръчките минават през pipeline-а (валидация, адреси/офиси) и влизат в таблото веднага.
Бърз старт
- 1От таблото отворете Настройки → Синхронизиране на поръчки.
- 2Запазете секрета. Показва се само при създаване.
- 3Изпратете поръчки към POST /orders/import с Bearer token за директен импорт.
Authentication
API ключ
Всяка заявка трябва да съдържа store-scoped ключ в `Authorization` header. Отменени или невалидни ключове връщат `401`. При създаване можете да ограничите правата (scopes).
Authorization: Bearer agl_live_ВАШИЯТ_КЛЮЧScopes (права)
Подразбиране е пълен достъп `*`. Можете да създадете ключ само с нужните права:
- `orders:write` — POST /orders/import, /orders/database, /orders/cancel
- `orders:read` — GET /orders/courier-status (`orders:write` също го покрива)
- `database:sync` — POST /orders/sync/database (+ `importToAgility`)
- `integration:read` — GET /integration
- Липсващ scope → `403`.
Endpoint
POST /orders/import
Директно в Agility
Директен импорт в Agility: валидация, мачване на адреси/офиси и запис в магазина. AgilityAI Engine е включен по подразбиране за Speedy BG/RO и Еконт BG — попълва град и site/city id при `siteStatus`/`VALID`; при `competingOfficeIds` иска избор на офис; прилага bookable ids при `engineStatus`/`VALID`/`autoValidBlocked`; при `destinationStatus`/`INVALID` иска по-добър адрес; несигурният `REVIEW_REQUIRED` остава за преглед. Изключва се с `useAddressResolver: false`.
POSTURLhttps://www.agility.bg/api/v1/orders/importBody{ orders: [...] }Endpoint
POST /orders/cancel
Анулация
Анулира поръчка в Agility по външен `code` (или `id`). При Speedy товарителница преди вземане първо се анулира в Спиди. При отказ от Спиди поръчката остава активна. Еконт се анулира само локално.
POSTURLhttps://www.agility.bg/api/v1/orders/cancelBody{ code, comment }curl -s -X POST \
-H "Authorization: Bearer agl_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"code":"1024","comment":"Customer requested cancellation"}' \
https://www.agility.bg/api/v1/orders/cancel{
"ok": true,
"order": {
"code": "1024",
"status": "cancelled",
"courier": "Speedy",
"waybill": "1234567890",
"deliveryType": "to_address"
},
"speedyCancel": "success"
}Endpoint
GET /orders/courier-status
Куриерски статус
Read-only: връща статуса на поръчката както е записан в Agility (Спиди или Еконт). Без live заявка към куриера. Query: `code` или `id`.
GETURLhttps://www.agility.bg/api/v1/orders/courier-status?code=1024Querycode | idcurl -s -X GET \
-H "Authorization: Bearer agl_live_YOUR_KEY" \
"https://www.agility.bg/api/v1/orders/courier-status?code=1024"{
"ok": true,
"order": {
"code": "1024",
"status": "sent",
"courier": "Speedy",
"waybill": "1234567890",
"deliveryType": "to_office"
}
}Reference
Payload fields
Body за `/orders/import`: опционално `useAddressResolver` и масив `orders`. Полетата по-долу са Shopify-съвместими; приемат се и snake_case alias-и (`order_code`, `customer_phone`, `cod_fee`…). Опционални са `COD Fee`, `Additional Names` и `Additional Prices`. `Subtotal` е без доставка; `Total` включва доставка, такса НП и допълнителни услуги, когато ги има. Има лимити за дължина на полетата (напр. адрес до 2000 символа, до 80 line items).
NamerequiredUnique order number (`order_code`). Rows with the same value in one request are grouped as one order. On `POST /orders/import`, if this code already exists in the store, the row is counted in `skippedExisting` and not inserted again.
EmailCustomer email. Stored when available.
Financial StatusPayment state. `paid` marks prepaid; `pending`/`unpaid` are treated as unpaid unless payment method says COD.
Paid atPayment timestamp. Compatibility field; usually optional.
Fulfillment StatusCompatibility field. Our system controls import status.
Fulfilled atCompatibility fulfillment timestamp.
Accepts MarketingCompatibility customer marketing flag.
CurrencyCurrency code, for example `EUR` or `BGN`.
SubtotalProduct subtotal without shipping. Used as fallback with `Shipping` and `Taxes` when `Total` is missing.
ShippingShipping amount charged to the customer.
TaxesTax amount. Used only for fallback total calculation.
TotalrequiredFinal order total and COD base for COD orders. Include shipping, COD fee, and extras when those apply.
COD FeeCustomer COD fee (not courier premium). Shown separately in the order breakdown. Alias: `cod_fee`.
Additional NamesComma-separated extra services, for example `1xosiguranje-paketa, 1xgarancija`. Imported as upsell lines. Alias: `additional_names`.
Additional PricesExtra-service prices: one combined sum, or comma-separated values matching the names. Alias: `additional_prices`.
Discount CodeDiscount code stored with the order.
Discount AmountDiscount amount stored with the order.
Shipping MethodrequiredDelivery method text, for example `Speedy to_address` or `Econt to_office`.
Created atOrder creation date/time in ISO 8601 format.
Lineitem quantityQuantity for this line item.
Lineitem namerequiredProduct name used in item display and shipment notes.
Lineitem priceProduct unit price.
Lineitem compare at priceFallback item price when `Lineitem price` is missing.
Lineitem skuProduct SKU.
Lineitem requires shippingCompatibility line item flag.
Lineitem taxableCompatibility line item tax flag.
Lineitem fulfillment statusCompatibility line item fulfillment state.
Billing NameFallback customer name if `Shipping Name` is missing.
Billing StreetFallback address if shipping address is missing.
Billing Address1Fallback address line.
Billing Address2Compatibility billing address line 2.
Billing CompanyCompatibility billing company.
Billing CityFallback city if `Shipping City` is missing.
Billing ZipFallback postal code if `Shipping Zip` is missing.
Billing ProvinceCompatibility billing region.
Billing CountryStored on the order for multi-country routing (fallback: `Shipping Country`).
Billing PhoneFallback phone if `Shipping Phone` is missing.
Shipping NamerequiredCustomer full name for delivery and waybill creation.
Shipping StreetFallback/alternative shipping address text.
Shipping Address1requiredMain delivery address text.
Shipping Address2Extra shipping address details.
Shipping CompanyCompatibility shipping company.
Shipping CityrequiredDelivery city used for courier city validation.
Shipping ZipPostal code. Strongly recommended for courier city matching.
Shipping ProvinceCompatibility shipping region.
Shipping CountryFallback country when `Billing Country` is empty.
Shipping PhonerequiredDelivery phone used for search, history, and waybills.
NotesCustomer note and optional pickup-office metadata from some integrations.
Note AttributesExtra metadata or item properties, used in shipment notes where possible.
Cancelled atCompatibility cancellation timestamp.
Payment MethodrequiredUse `Cash on Delivery (COD)` for COD orders; otherwise send the prepaid provider/name.
Payment ReferenceCompatibility external payment reference.
Refunded AmountCompatibility refunded amount.
VendorCompatibility vendor field.
Outstanding BalanceCompatibility outstanding balance.
EmployeeCompatibility POS employee field.
LocationCompatibility Shopify location/POS field.
Device IDCompatibility POS device field.
IdExternal/Shopify id. `Name` is still used as display order code.
TagsScanned for risk/report markers and customer verification display.
Risk LevelCompatibility Shopify risk level.
SourceSource channel, useful for debugging.
Lineitem discountCompatibility per-line discount.
PhoneFallback phone field.
CourierrequiredAPI-specific courier column. Allowed values: `Speedy`, `Econt`.
Example
Примерна заявка (директен импорт)
curl -s -X POST -H "Authorization: Bearer agl_live_KEY" -H "Content-Type: application/json" -d '{
"orders": [
{
"Name": "#25001",
"Created at": "2026-05-18T09:36:39.285Z",
"Shipping Name": "Ivan Petrov",
"Email": "ivan@example.com",
"Shipping Phone": "0888123456",
"Subtotal": 13.90,
"Shipping": 3.50,
"Total": 20.00,
"COD Fee": 1.60,
"Additional Names": "1xosiguranje-paketa",
"Additional Prices": 1,
"Lineitem quantity": 2,
"Lineitem name": "Product A",
"Lineitem price": 6.95,
"Shipping Method": "Speedy to_address",
"Shipping Address1": "bul. Bulgaria 1",
"Shipping City": "Sofia",
"Shipping Zip": "1000",
"Billing Country": "BG",
"Courier": "Speedy",
"Financial Status": "pending",
"Payment Method": "Cash on Delivery (COD)",
"Note Attributes": ""
}
]
}' https://www.agility.bg/api/v1/orders/importПример — анулация
curl -s -X POST \
-H "Authorization: Bearer agl_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"code":"1024","comment":"Customer requested cancellation"}' \
https://www.agility.bg/api/v1/orders/cancelПример — куриерски статус
curl -s -X GET \
-H "Authorization: Bearer agl_live_YOUR_KEY" \
"https://www.agility.bg/api/v1/orders/courier-status?code=1024"Responses
Отговори
200 — /orders/import
Дубликати: ако `Name` (код на поръчката) вече съществува в същия магазин, редът не се създава отново. Броят им е в `skippedExisting`. Поръчката не се презаписва изцяло; при повторно изпращане могат да се обновят само някои полета (напр. отстъпка/плащане). Еднакви кодове в една заявка се дедуплицират преди запис.
{
"ok": true,
"useAddressResolver": true,
"imported": 1,
"skippedExisting": 0,
"totalReadyForImport": 1,
"totalInFile": 1,
"skipped": 0,
"parseErrors": [],
"results": [
{ "name": "1024", "status": "imported", "id": 50122 }
]
}okВинаги `true` при успешен HTTP 200.
useAddressResolverДали AgilityAI address resolver е бил активен за тази заявка (по подразбиране `true`; изключва се с `useAddressResolver: false` в body).
importedКолко нови поръчки са записани в Agility при тази заявка.
skippedExistingКолко валидни реда са пропуснати, защото кодът (`Name`) вече съществува в магазина.
totalReadyForImportКолко реда са минали валидацията и са готови за запис (преди филтъра за дубликати).
totalInFileОбщ брой подадени поръчки в заявката (вкл. невалидни).
skippedБрой редове с parse грешки (невалидни данни); вижте `parseErrors`.
parseErrorsСписък `{ line, reason, name? }` за редове, които не са приети заради валидация (`name` е нормализираният код, когато е известен).
results`results[]` — резултат за всяка подадена поръчка по нормализиран `Name`: `imported` (+ `id`), `skipped_existing`, `skipped_duplicate_in_request`, или `error` (+ `reason`, опционално `line`).
Отговорът може да включва и статистика от pipeline-а (`officeMatched`, `cityErrors`, `statusBreakdown`, `nekorekten`, `timings`, `insertedIds` и др.) — за диагностика, не са задължителни за интеграцията.
4xx / 5xx
`401` невалиден ключ · `403` липсва scope · `409` импорт вече тече · `429` rate limit (Retry-After) · `400`/`422` невалидни данни или над лимитите (500 поръчки / дълги полета).
Security
Сигурност
- Използвайте само HTTPS в production.
- Всеки ключ е ограничен до един магазин.
- Използвайте scopes за least privilege, когато интеграцията не трябва пълен достъп.
- Rate limits: ~60 req/min на IP; ~30/min на ключ за import/database/cancel; ~120/min за леки GET (вкл. courier-status). При превишаване → `429`.
- Паралелен sync от базата данни за същия магазин се блокира с `409` (Retry-After).
- При съмнение отменете ключа и създайте нов.