Для загрузки больших объемов данных стандартные методы API не удобны в плане кол-ва запросов (1 запрос — 1 ресурс) и времени выполнения. Чтобы оптимизировать и упростить процесс импорта необходимо использовать метод импорта.
Тело запроса для метода импорта имеет следующие параметры:
{ "dataType": "orders", "actionType": "create", "data": [{...}, {...}, {...}] }
В качестве параметра data должен быть массив объектов. Эти объекты идентичны тем, что используются в обычных методах API. Другими словами модели данных одинаковы.
Запрос на импорт данных возвращает 202 код состояния HTTP. Это значит, что запрос был принят на обработку, но она не завершена. Импорт данных выполняется асинхронно и не требует активного клиентского соединения до окончания операции.
В теле ответа содержится уникальный идентификатор запроса, по которому можно получить статус выполнения запроса на импорт.
{ "id": "84935707-e53e-4f63-8381-a48bfc420c6b" }
{ "id":"84935707-e53e-4f63-8381-a48bfc420c6b", "status":"сompleted", "startedOnUtc":"2017-09-28T10:13:50.8889015Z", "completePercent":100.0, "completedOnUtc":"2017-09-28T10:14:38.5171111Z" }
DataType | ActionType |
---|---|
Products (продукты) | Create, Update, CreateOrUpdate |
ProductPrices (цены на продукты) | Replace |
InvoiceDebts (долги по накладным) | Replace |
RelationshipDebts (долги по договорам) | Replace |
Customers (клиенты) | Create, Update, CreateOrUpdate |
Relationships (договора) | Create, Update, CreateOrUpdate |
TradeOutlets (договора) | Create, Update, CreateOrUpdate |
Tasks (договора) | Create |
PersonalPrices (персональные цены) | Replace |
ProductImages (изображения продукции) | CreateOrUpdate |
{ "actionType":"Replace", "dataType":"RelationshipDebts", "data":[ { "relationshipId":"000000044", "Debts":[ { "CurrencyId":"980", "Sum":3326 } ], "OverdueDebts":[ ] }, { "relationshipId":"000000402", "Debts":[ { "CurrencyId":"980", "Sum":23415.55 } ], "OverdueDebts":[ { "CurrencyId":"980", "Sum":3326 } ] } ] }
{ "actionType":"Replace", "dataType":"InvoiceDebts", "data":[ { "invoiceId":"906b0048-2068-11e8-80fe-00155d000703", "Debts":[ { "CurrencyId":"980", "Sum":2032 } ] }, { "invoiceId":"93eeccd4-25cd-11e8-8101-00155d000703", "Debts":[ { "CurrencyId":"980", "Sum":5105 } ] } ] }
{ "actionType":"Replace", "dataType":"ProductPrices", "data":[ { "ProductId":"000000009", "PriceCategoryId":"000000002", "Price":16, "CurrencyId":"980" }, { "ProductId":"000005453", "PriceCategoryId":"000000002", "Price":43, "CurrencyId":"980" } ] }
{ "actionType":"Replace", "dataType":"PersonalPrices", "data":[ { "TradeOutletId": "10", "GroupId": "1234567", "BrandId": null, "CurrencyId": "UAH", "Price": null, "Discount": 20 }, { "TradeOutletId": "11", "GroupId": "1234568", "BrandId": null, "CurrencyId": "UAH", "Price": null, "Discount": 15 } ] }
{ "actionType":"Create", "dataType":"Customers", "data":[ { "vendorId": "1234567890", "name": "ООО Светлячок", "taxNumber": "123456789", "location": { "countryId": "UKR", "provinceId": "E5A6AAE5-7BAC-4C94-92E8-D07D84C1F18E", "addressLine": "ул. Дегтяревская 28", "geoCoordinate": { "latitude": 50.462504, "longitude": 30.469118 }, "settlement": "Киев" }, "tradeNetworkId": NULL, "officeId": "FAD3D784-6A79-4AF8-BF66-DB214FADEF11" }, { "vendorId": "1234567891", "name": "ООО Светлячок 2", "taxNumber": "123456780", "location": { "countryId": "UKR", "provinceId": "E5A6AAE5-7BAC-4C94-92E8-D07D84C1F18E", "addressLine": "ул. Дегтяревская 25", "geoCoordinate": { "latitude": 50.462524, "longitude": 30.469108 }, "settlement": "Киев" }, "tradeNetworkId": NULL, "officeId": "FAD3D784-6A79-4AF8-BF66-DB214FADEF11" } ] }
{ "actionType":"Create", "dataType":"Relationships", "data":[ { "vendorId": "12345", "name": "Договор № 12345", "customerId": "a01bd685-e1d3-e511-80c8-000d3a227db5", "currencyId": "USD", "priceCategoryId": "1a173bed-ff2f-4e38-98e0-0061891898bf", "deferment": 10, "limit": 1000.0, "active": true, "dateFrom": "2018-01-01", "dateTill": "2019-01-01", "orderIndex": 1, "priceTiers": [ "3ef6a4c3-fb0d-e611-80c8-000d3a209210", "5509132d-8bfa-4e26-a95c-024e5087b745" ], "paymentTypeIds": [ "000003449", "000003450" ], "paymentForms": [ 1 ], "deliveryTypeIds": [ "23467841", "23685682" ], "debts": [ { "currencyId": "USD", "sum": 152.0 } ], "overdueDebts": [ { "currencyId": "USD", "sum": 52.0 } ] }, { "vendorId": "12345", "name": "Договор № 12345", "customerId": "a01bd685-e1d3-e511-80c8-000d3a227db5", "currencyId": "USD", "priceCategoryId": "1a173bed-ff2f-4e38-98e0-0061891898bf", "deferment": 10, "limit": 1000.0, "active": true, "dateFrom": "2018-01-01", "dateTill": "2019-01-01", "orderIndex": 1, "priceTiers": [ "3ef6a4c3-fb0d-e611-80c8-000d3a209210", "5509132d-8bfa-4e26-a95c-024e5087b745" ], "paymentTypeIds": [ "000003449", "000003450" ], "paymentForms": [ 1 ], "deliveryTypeIds": [ "23467841", "23685682" ], "debts": [ { "currencyId": "USD", "sum": 152.0 } ], "overdueDebts": [ { "currencyId": "USD", "sum": 52.0 } ] } ] }
{ "actionType":"Replace", "dataType":"ProductPrices", "data":[ { "name": "import_update_2", "location": { "countryId": "UKR", "provinceId": "E5A6AAE5-7BAC-4C94-92E8-D07D84C1F18E", "addressLine": "address line here", "geoCoordinate": { "latitude": 1.1, "longitude": 1.1 }, "settlement": "kyiv" }, "categoryId": "D41D97EB-6ECC-4AED-B9BE-4FCA3411D2C8", "formatId": "FAD3D784-6A79-4AF8-BF66-DB214FADEF11", "freeVisit": false, "relationships": [ { "relationshipId": "359294CF-B893-45E9-AE79-0B498929985F", "orderIndex": 1 }, { "relationshipId": "25275539-93CA-477A-85C9-0D83859CEDC7", "orderIndex": 2 } ], "properties": [ { "propertyId": "67D8267B-46C4-E511-80C6-0003FF4B7B03", "value": "12" }, { "propertyId": "76C35E32-BFD3-E511-80C8-000D3A227DB5", "value": "22" } ] }, { "name": "import_update_2", "location": { "countryId": "UKR", "provinceId": "E5A6AAE5-7BAC-4C94-92E8-D07D84C1F18E", "addressLine": "address line here", "geoCoordinate": { "latitude": 1.1, "longitude": 1.1 }, "settlement": "kyiv" }, "categoryId": "D41D97EB-6ECC-4AED-B9BE-4FCA3411D2C8", "formatId": "FAD3D784-6A79-4AF8-BF66-DB214FADEF11", "freeVisit": false, "relationships": [ { "relationshipId": "359294CF-B893-45E9-AE79-0B498929985F", "orderIndex": 1 }, { "relationshipId": "25275539-93CA-477A-85C9-0D83859CEDC7", "orderIndex": 2 } ], "properties": [ { "propertyId": "67D8267B-46C4-E511-80C6-0003FF4B7B03", "value": "12" }, { "propertyId": "76C35E32-BFD3-E511-80C8-000D3A227DB5", "value": "22" } ] } ] }
{ "dataType": "ProductImages", "actionType": "CreateOrUpdate", "data": [ { "productId": "2", "images": [ { "orderIndex": 1, "Url": "http://writingexercises.co.uk/images2/randomimage/slimy.jpg" }, { "orderIndex": 2, "Url": "http://writingexercises.co.uk/images2/randomimage/fruit-stall.jpg" } ] } ] }
{ "dataType": "ProductImages", "actionType": "CreateOrUpdate", "data": [ { "productId": "6", "images": [ { "orderIndex": 1, "content": "/9j/4AAQSkZJRgABAQEAwIUp5niqdO9HAxr1fYUXiZynDkdSt+7hFRqTck/cUYylHvrY/BYfEYTC18VRpYnHyqRwVCc73FY223UCk9Btfa+0egfI7UAfBNFfS+s/sv+NrIu2lX+l6tGMlVLyWkxH0lDRg/9tMH2VcVKlT9rU9jFRlzKFP3pSbhFJr3m2ov8ARKiiivPOsKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKAKKKKAKKACiiigAooooAKKKKACiAKKKKAiigAooooAKKKKAKKKKAACiiigAAKKKKAooooAKKKKAP/2Q==" }, { "orderIndex": 2, "content": "/9j/4AAQSkZJRgABAQEASABea8S139lzwrel5NG1K+0l23FY223UCk9Btfa+0egfI7UAfBNFfS+s/sv+NrIu2lX+l6tGMlVLyWkxH0lDRg/9tMH2rzPU/g/8RdKLfafDF86rnL2oW6TA7hoWbI70AeaUVs3Ph3XrMlbrR9SgI6iWznXHOOcpjrWW8E0ZIeGVCDgho3Xn8QKAIqKXBHUH8jSUAFFLg+h/KnrFK/CxSMfRUY/yBoAjorVt9C1q7IW20rUJyegitJ3z9MJiuu034UfEHVSv2TwvqW1ujzxfZ0/FpigH40AeeUV9G6P+zJ4+vyjajNpmkRnG4SzNcygHrhIAUyPQuPrXrmhfsr6DalH13WrzUXGC8Vsi2sJPoD88hHYncD6UAfDCo7kKis7HgKqliT6AAEmvQvDXwr8deKmQ6ZoN2luxGby8ja0tgp6sHmCmQDr+7DV+iXh/4WeBfDQRtN0CyEyYxcXES3E+RjnfKGweOoxXoCoiAKiqigYAUAAD0AAFAHyB4S/ZbtIjFc+LdUe5I2s9hYZjiPAJR5mG8jJwSoGccEV9NeHvBvhnwrbrbaFpKKKACiiigAooooA/9k=" } ] } ] }