Skip to content

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.

  1. Call getUploadToken with the upload type and the tariff or destination set. It returns a unique token and the url to send the file to. You can also set when processing starts and how long the URL stays valid.
  2. Send the file to url with an HTTP POST and chunked transfer encoding.
  3. Poll getUploadStatus with the token. When processing ends, it returns the url of 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.

upload the file
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 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.

  • The upload URL accepts one file per token, until expires_on of 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.