Rust for Uploading Documents in Rossum API

This Rust code shows how to upload a document automatically using Rossum API to a particular Rossum queue.

This Rust code demonstrates how to upload a document using Rossum API to a particular Rossum queue. Set the options at the beginning of the script – they store your credentials, and also the identifier of the queue to upload in. You can find out the queue id by looking at your main screen URL, it is the number 12345 in

See the reference API documentation for more details about how to use the upload API.

name = "rossum_api_examples"
version = "0.1.0"
authors = ["Bohumir Zamecnik <[email protected]>"]
edition = "2018"

# See more keys and their definitions at

reqwest = "^0.9"
serde = "^1"
serde_derive = "^1"
serde_json = "^1"
chrono = "^0.4"
extern crate chrono;
extern crate reqwest;
extern crate serde_derive;
extern crate serde_json;

use std::collections::HashMap;
use chrono::{DateTime, Duration, Utc};
use reqwest::multipart;

#[derive(Debug, Deserialize)]
struct LoginResponse {
    key: String,

fn authorize(username: &str, password: &str) -> Result<String, Box<std::error::Error>> {
    let login_url = "";
    let mut credentials = HashMap::new();
    credentials.insert("username", username);
    credentials.insert("password", password);
    let client = reqwest::Client::new();
    let response =
    let login_response = response?.json::<LoginResponse>()?;
    let auth_token = login_response.key;

fn upload(queue_id: &str, file_path: &str, auth_token: &str) -> Result<(), Box<std::error::Error>> {
    let client = reqwest::Client::new();
    let url = format!("{}/upload", queue_id);
    let attachment = multipart::Form::new().file("content", file_path)?;    
    let response =
        .header("Authorization", format!("token {}", auth_token))

    println!("{}", response?.text()?);

fn main() -> Result<(), Box<std::error::Error>> {
    let username = "[email protected]";
    let password = "secret_password";
    let queue_id = "12345";
    let file_path = "invoice.pdf";
    let auth_token = authorize(username, password)?;
    upload(&queue_id, &file_path, &auth_token)?;