Binary upload
Это содержимое пока не доступно на вашем языке.
Binary upload loads many rates into a tariff, or many routes into a destination set, in one file instead of thousands of API calls. You ask the switch for an upload URL, send the file to it, and the switch processes the file in the background and keeps a report. It works for two kinds of data: rates of a tariff and routes of a destination set.
How it works
Section titled “How it works”- Call
getUploadTokenwith the upload type and the tariff or destination set. It returns a uniquetokenand theurlto send the file to. You can also set when processing starts and how long the URL stays valid. - Send the file to
urlwith an HTTPPOSTand chunked transfer encoding. - Poll
getUploadStatuswith the token. When processing ends, it returns theurlof the report.
The upload URL answers with JSON: {"result": "OK"} when the file is stored, or {"result": "FAIL", "error": "Unable to copy data"} when the token is unknown, already used or expired. A request other than POST gets HTTP 405.
import requests
token = call("getUploadToken", {"i_upload_type": 2, "params": {"i_tariff": 12}})
def chunks(path, size=1 << 20): with open(path, "rb") as f: while block := f.read(size): yield block
# A generator body makes requests use chunked transfer encoding.resp = requests.post(token["url"], data=chunks("rates.csv"), timeout=300)print(resp.json()) # {"result": "OK"}The file
Section titled “The file”The file has the same columns as the file you get with Download on the rates or routes screen of the panel, starting with the Action column (A add, U update by Id, S update by prefix, SA add or update, D delete). The simplest way to build one is to download the current rates or routes, edit them and upload the result. See Rates and General method for uploading data.
Limits
Section titled “Limits”- The upload URL accepts one file per token, until
expires_onof the token. - A rates upload needs a customer that may edit tariffs; a routes upload needs a customer with system management rights. Otherwise the upload ends with
FAIL. - While a file is processed, the panel does not let you add, change or delete rates of that tariff or routes of that destination set.
- Processing that runs longer than one day is stopped and the upload is set to
FAIL. - The report is stored on the node that received the file. The upload and its report are deleted one week after
process_on.
Related
Section titled “Related”- Get an upload token
- Get the status of an upload
- Rates and Destination sets: the same upload in the panel
- Get system dictionaries: the
upload_typesdictionary