Skip to content
Docs
API 1.0.0 · 23 Nov 2026

Search the docs

    Română

    Bulk import

    File documents that were approved elsewhere straight into the archive, one request per document, and run the import again safely after a failure.

    On this page

    importDocument files a document that was approved elsewhere straight as archived. It has no approval and no signature, and nothing changes on it afterwards. Send one request for each document, with its own operationId.

    curl

    curl -X POST "$RDC_BASE_URL/documents/v1/imports" \
      -H "Authorization: Bearer $RDC_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
      "operationId": "df39276c-f803-47ea-acae-b3af65ffc67c",
      "class": "invoice",
      "name": "Invoice MV-2018-0311",
      "counterpartyId": "365fcde1-a8f1-4abc-bff5-001cc36ad963",
      "project": "Imported archive",
      "date": "2018-04-12",
      "amount": "4310.50",
      "owner": "ioana-marin",
      "file": {
        "name": "MV-2018-0311.pdf",
        "mediaType": "application/pdf",
        "content": "JVBERi0xLjcKJeLjz9MKJSVFT0YK"
      }
    }'

    JavaScript

    const response = await fetch(`${process.env.RDC_BASE_URL}/documents/v1/imports`, {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.RDC_TOKEN}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        "operationId": "df39276c-f803-47ea-acae-b3af65ffc67c",
        "class": "invoice",
        "name": "Invoice MV-2018-0311",
        "counterpartyId": "365fcde1-a8f1-4abc-bff5-001cc36ad963",
        "project": "Imported archive",
        "date": "2018-04-12",
        "amount": "4310.50",
        "owner": "ioana-marin",
        "file": {
          "name": "MV-2018-0311.pdf",
          "mediaType": "application/pdf",
          "content": "JVBERi0xLjcKJeLjz9MKJSVFT0YK"
        }
      }),
    });
    const result = await response.json();

    Python

    import os
    import requests
    
    response = requests.request(
        'POST',
        f'{os.environ["RDC_BASE_URL"]}/documents/v1/imports',
        headers={
            'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
        },
        json={
            'operationId': 'df39276c-f803-47ea-acae-b3af65ffc67c',
            'class': 'invoice',
            'name': 'Invoice MV-2018-0311',
            'counterpartyId': '365fcde1-a8f1-4abc-bff5-001cc36ad963',
            'project': 'Imported archive',
            'date': '2018-04-12',
            'amount': '4310.50',
            'owner': 'ioana-marin',
            'file': {
                'name': 'MV-2018-0311.pdf',
                'mediaType': 'application/pdf',
                'content': 'JVBERi0xLjcKJeLjz9MKJSVFT0YK',
            },
        },
    )
    result = response.json()

    PHP

    <?php
    
    $body = <<<'JSON'
    {
      "operationId": "df39276c-f803-47ea-acae-b3af65ffc67c",
      "class": "invoice",
      "name": "Invoice MV-2018-0311",
      "counterpartyId": "365fcde1-a8f1-4abc-bff5-001cc36ad963",
      "project": "Imported archive",
      "date": "2018-04-12",
      "amount": "4310.50",
      "owner": "ioana-marin",
      "file": {
        "name": "MV-2018-0311.pdf",
        "mediaType": "application/pdf",
        "content": "JVBERi0xLjcKJeLjz9MKJSVFT0YK"
      }
    }
    JSON;
    
    $curl = curl_init(getenv('RDC_BASE_URL') . '/documents/v1/imports');
    curl_setopt_array($curl, [
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('RDC_TOKEN'),
            'Content-Type: application/json',
        ],
        CURLOPT_POSTFIELDS => $body,
    ]);
    $result = json_decode(curl_exec($curl), true);
    curl_close($curl);

    C#

    using System.Net.Http.Headers;
    
    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/documents/v1/imports");
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
    request.Content = new StringContent("""
    {
      "operationId": "df39276c-f803-47ea-acae-b3af65ffc67c",
      "class": "invoice",
      "name": "Invoice MV-2018-0311",
      "counterpartyId": "365fcde1-a8f1-4abc-bff5-001cc36ad963",
      "project": "Imported archive",
      "date": "2018-04-12",
      "amount": "4310.50",
      "owner": "ioana-marin",
      "file": {
        "name": "MV-2018-0311.pdf",
        "mediaType": "application/pdf",
        "content": "JVBERi0xLjcKJeLjz9MKJSVFT0YK"
      }
    }
    """, System.Text.Encoding.UTF8, "application/json");
    var response = await client.SendAsync(request);
    var result = await response.Content.ReadAsStringAsync();

    Response 202

    {
      "operationId": "df39276c-f803-47ea-acae-b3af65ffc67c",
      "status": "accepted",
      "aggregateRevision": 1,
      "documentId": "ba4d0edc-7dd5-41e9-82ab-0ed0b4c95fa6",
      "number": "DOC-2026-0403"
    }

    The answer carries the documentId and the number of the document, here DOC-2026-0403. The document is archived at revision 1. Its keepUntil is 2028-12-31: the rule of its class applied to the date on the document, 2018-04-12, not to the day of the import.

    Read the outcome by the operationId you sent. An import is not read for values: it has no extract.

    Get the operation of an import

    curl

    curl "$RDC_BASE_URL/documents/v1/operations/df39276c-f803-47ea-acae-b3af65ffc67c" \
      -H "Authorization: Bearer $RDC_TOKEN"

    JavaScript

    const response = await fetch(`${process.env.RDC_BASE_URL}/documents/v1/operations/df39276c-f803-47ea-acae-b3af65ffc67c`, {
      method: 'GET',
      headers: {
        Authorization: `Bearer ${process.env.RDC_TOKEN}`,
      },
    });
    const result = await response.json();

    Python

    import os
    import requests
    
    response = requests.request(
        'GET',
        f'{os.environ["RDC_BASE_URL"]}/documents/v1/operations/df39276c-f803-47ea-acae-b3af65ffc67c',
        headers={
            'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
        },
    )
    result = response.json()

    PHP

    <?php
    
    $curl = curl_init(getenv('RDC_BASE_URL') . '/documents/v1/operations/df39276c-f803-47ea-acae-b3af65ffc67c');
    curl_setopt_array($curl, [
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('RDC_TOKEN'),
        ],
    ]);
    $result = json_decode(curl_exec($curl), true);
    curl_close($curl);

    C#

    using System.Net.Http.Headers;
    
    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/documents/v1/operations/df39276c-f803-47ea-acae-b3af65ffc67c");
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
    var response = await client.SendAsync(request);
    var result = await response.Content.ReadAsStringAsync();

    Response 200

    {
      "operationId": "df39276c-f803-47ea-acae-b3af65ffc67c",
      "status": "completed",
      "aggregateRevision": 1,
      "documentId": "ba4d0edc-7dd5-41e9-82ab-0ed0b4c95fa6"
    }

    Prepare the rows

    • Give every row the class, the name, the date on the document, the owner and the file. The amount, the counterpartyId and the project are optional.
    • Send the date that is printed on the document, as YYYY-MM-DD. It sets the keep-until date.
    • Name an owner that is a person of your account, and a counterpartyId that is a customer, a supplier or a carrier of your account.
    • Keep each file within 10 MiB, as application/pdf, image/png, image/jpeg or image/tiff, and each name within 280 characters.

    One request, one document

    Fix the operationId of a row before the first request, so that the same row always sends the same request. Derive it from a name that does not change between runs, such as the path of the file, with a UUID of version 5 under one fixed namespace. Or store it in a map next to the row. The two scripts show both.

    Import a list of documents

    Bash

    #!/usr/bin/env bash
    # documents.txt: one document per line, fields separated by |
    #   file|class|name|counterpartyId|project|date|amount
    # ids.txt keeps the operationId of each file, so a second run sends the same ones.
    touch ids.txt results.txt
    while IFS='|' read -r file class name counterparty project date amount; do
      id=$(awk -F'|' -v f="$file" '$1 == f {print $2}' ids.txt)
      if [ -z "$id" ]; then
        id=$(uuidgen | tr 'A-Z' 'a-z')
        echo "$file|$id" >> ids.txt
      fi
      jq -n --arg operationId "$id" --arg class "$class" --arg name "$name" \
        --arg counterpartyId "$counterparty" --arg project "$project" --arg date "$date" --arg amount "$amount" \
        --arg owner "ioana-marin" --arg fileName "$(basename "$file")" \
        --rawfile content <(base64 < "$file" | tr -d '\n') \
        '{operationId: $operationId, class: $class, name: $name, counterpartyId: $counterpartyId, project: $project,
          date: $date, amount: $amount, owner: $owner,
          file: {name: $fileName, mediaType: "application/pdf", content: $content}}
         | with_entries(select(.value != ""))' > body.json
      while true; do
        status=$(curl -sS -D headers.txt -o answer.json -w '%{http_code}' \
          -X POST "$RDC_BASE_URL/documents/v1/imports" \
          -H "Authorization: Bearer $RDC_TOKEN" -H 'Content-Type: application/json' \
          --data @body.json)
        case "$status" in
          429)
            wait=$(awk 'tolower($1) == "retry-after:" {print $2 + 0}' headers.txt)
            sleep "${wait:-5}" ;;
          503) sleep 5 ;;
          *) break ;;
        esac
      done
      echo "$file|$status|$(jq -r '.number // .code' answer.json)" >> results.txt
    done < documents.txt
    

    JavaScript

    // import.mjs, run with: node import.mjs documents.json
    import {createHash} from 'node:crypto';
    import {readFileSync} from 'node:fs';
    import {basename} from 'node:path';
    
    // One fixed namespace for the whole import. Do not change it between runs.
    const NAMESPACE = '6f1c2b4e-8a3d-5c97-b0e1-2d4f6a8c0e13';
    
    // A version 5 UUID: the same file name always gives the same operationId.
    const operationIdOf = name => {
      const hash = createHash('sha1').update(Buffer.from(NAMESPACE.replaceAll('-', ''), 'hex')).update(name).digest();
      hash[6] = (hash[6] & 0x0f) | 0x50;
      hash[8] = (hash[8] & 0x3f) | 0x80;
      const hex = hash.subarray(0, 16).toString('hex');
      return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
    };
    
    const pause = seconds => new Promise(resolve => setTimeout(resolve, seconds * 1000));
    
    // Sends one request, and the same request again after a 429, a 503 or a network error.
    async function send(body) {
      for (;;) {
        let response;
        try {
          response = await fetch(`${process.env.RDC_BASE_URL}/documents/v1/imports`, {
            method: 'POST',
            headers: {Authorization: `Bearer ${process.env.RDC_TOKEN}`, 'Content-Type': 'application/json'},
            body: JSON.stringify(body),
          });
        } catch {
          await pause(5);
          continue;
        }
        if (response.status === 429 || response.status === 503) {
          await pause(Number(response.headers.get('Retry-After') ?? 5));
          continue;
        }
        return {status: response.status, answer: await response.json()};
      }
    }
    
    const rows = JSON.parse(readFileSync(process.argv[2], 'utf8'));
    for (const row of rows) {
      const {status, answer} = await send({
        operationId: operationIdOf(row.file),
        class: row.class, name: row.name, counterpartyId: row.counterpartyId, project: row.project,
        date: row.date, amount: row.amount, owner: row.owner,
        file: {name: basename(row.file), mediaType: row.mediaType, content: readFileSync(row.file).toString('base64')},
      });
      console.log(row.file, status, answer.number ?? answer.code);
    }
    

    Both scripts send the same request again after a 429 or a 503. The bash script reads Retry-After from the answer; the JavaScript script does the same and also repeats a request that ended in a network error.

    Run it again after a failure

    Run the whole list again. A row that was filed sends the same request with the same operationId, so it gets its first outcome and nothing is filed twice. A row that was not filed is filed now. Retry-After gives the seconds to wait after a 429: pause, then send the same request with the same operationId.

    Check the progress

    Read the operation of each row, as above, or list the archive. listDocuments has no filter by project; use status, class, owner and keepUntilBefore. Follow nextCursor to the end, and compare the number of each document with the ones you stored.

    List the archived invoices of the owner

    curl

    curl "$RDC_BASE_URL/documents/v1/documents?status=archived&class=invoice&owner=ioana-marin&limit=100" \
      -H "Authorization: Bearer $RDC_TOKEN"

    JavaScript

    const response = await fetch(`${process.env.RDC_BASE_URL}/documents/v1/documents?status=archived&class=invoice&owner=ioana-marin&limit=100`, {
      method: 'GET',
      headers: {
        Authorization: `Bearer ${process.env.RDC_TOKEN}`,
      },
    });
    const result = await response.json();

    Python

    import os
    import requests
    
    response = requests.request(
        'GET',
        f'{os.environ["RDC_BASE_URL"]}/documents/v1/documents?status=archived&class=invoice&owner=ioana-marin&limit=100',
        headers={
            'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
        },
    )
    result = response.json()

    PHP

    <?php
    
    $curl = curl_init(getenv('RDC_BASE_URL') . '/documents/v1/documents?status=archived&class=invoice&owner=ioana-marin&limit=100');
    curl_setopt_array($curl, [
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('RDC_TOKEN'),
        ],
    ]);
    $result = json_decode(curl_exec($curl), true);
    curl_close($curl);

    C#

    using System.Net.Http.Headers;
    
    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/documents/v1/documents?status=archived&class=invoice&owner=ioana-marin&limit=100");
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
    var response = await client.SendAsync(request);
    var result = await response.Content.ReadAsStringAsync();

    Each import also sends a document.imported event with the number, the class and the keepUntil of the document. See the Event catalogue.

    Codes and what to do

    CodeStatusCauseWhat to do
    class_not_valid422The class is not one of the four classes.No retry. Correct the row.
    name_required422The name is empty or longer than 280 characters.No retry. Correct the row.
    date_not_valid422The date is not a real day in the form YYYY-MM-DD.No retry. Correct the row.
    amount_not_valid422The amount is not a decimal string above zero with at most two decimals.No retry. Correct the row.
    counterparty_not_found404The counterpartyId is not a partner of your account.No retry. Correct the row.
    person_not_found404The owner is not a person of your account.No retry. Correct the row.
    invalid_request400A field is missing, or the file has a wrong media type, is not base64 or is over 10 MiB.No retry. fields names each one; correct the row.
    operation_reused409The row changed after it was filed, and the operationId is the same.The document stays as it was filed. A new operationId files a second document, so use one only when you want it.
    rate_limited429Too many requests. The request was not processed.Wait the seconds in Retry-After, then send the same request with the same operationId.
    unavailable503The service cannot answer now.Send the same request again with the same operationId.