License Management API

<< Click to Display Table of Contents >>

Raynet One > 2026.4 > User Guide > Technical overview > API 

License Management API

The License Management API imports purchase and agreement documents into License Management through the REST API, for example from a document management or procurement system. It uses the same import as the Import from file and Import from files options of the Add purchase wizard. For the data that is extracted from the documents, see Contract Analyzer. Text is processed through the AI Chat connection, as with Enter text.

 

The endpoints are available under /api/v1/purchases. The API key must belong to a user with the Administrator role, and the License Management license is required. For the API key header, the HTTP verbs and the request format, see API.

 

Endpoints

•POST import-file: Imports one purchase document, sent as the multipart form field file. The response is returned when the purchase is saved.

•POST import-text: Imports one purchase from plain text, sent as the request body with the content type text/plain. The response is returned when the purchase is saved.

•POST import-multiple: Imports several purchase and agreement documents in one batch. The response contains a session ID right away; the files are processed in the background.

•POST import: Imports one document, sent as a file or as text. With a file, the document is processed like a batch of one: the response contains a session ID that you must poll with import-progress. With text, the response is returned when the purchase is saved.

•GET import-progress/{sessionId}: Returns the progress and the result per file of a batch import. The result stays available for 5 minutes after the batch has finished; for an unknown or expired session ID the endpoint answers 404.

•GET {id}: Returns a purchase with its purchase items, customer and supplier.

•POST import: Accepts either a file or a text. A file is processed in the background like a batch with one file, a text is imported directly.

 

The endpoints import (with a file) and import-multiple detect whether a document is a purchase or an agreement. The endpoints import-file and import-text always import a purchase; do not send agreement documents to them.

 

Unlike in the Add purchase wizard, there is no review step. The purchase is saved directly. Review the imported purchases afterwards on the Purchases tab of the Documents page.

 

Import options

For import-file and import-text, pass the options as query parameters. For import-multiple and import, pass them as multipart form fields. Values can be passed by name or by number.

•minimumProductConfidence: 0 to 100, default 90.

•importMode: Strict (default) or Partial.

•relationMode (only import-multiple): NoRelation (default), GroupRelation or ProductBasedRelation.

•files[n].id, files[n].file and files[n].documentTypeHint (only import-multiple): one entry per file, numbered from 0 without gaps. The ID is returned with the result of the file. The document type hint is NoHint (default, SAM AI detects the type), Procurement or Agreement.

 

The options have the same meaning as in Import from files.

 

Limits and errors

Supported files are PDF, PNG, JPEG and TIFF. The maximum size per file, the maximum total size and the maximum number of files are the same as in the wizard and can be changed under License Management settings. An invalid request is answered with status 400, the reason is listed in logs.

 

Each import result contains success, documentType, procurementId and procurementName or agreementId and agreementName, the matched commercialProducts and the logs of the import. For the complete request and response layout, see the swagger.json file referenced in API.

 

Purchases and agreements created through the import endpoints are not approved yet. They are approved in the user interface, see Purchase view and License Agreements.

 

Requirements

•Python 3+

•Requests library (https://docs.python-requests.org/en/latest/)

•API key of a user with the Administrator role

•frontend URL

•SAM Cloud connection configured, see SAM Cloud Connection

•for import-text: AI Chat connection configured

 

Program content: import a purchase document

import mimetypes
import os
import requests
 
APIKEY = "PUT API KEY HERE"
FRONTEND = "PUT FRONTEND URL HERE"
DOCUMENT = "PUT PATH TO PURCHASE DOCUMENT HERE"
 
HEADERS = { "ApiKey": APIKEY }
 
def main():
    name = os.path.basename(DOCUMENT)
    mime = mimetypes.guess_type(DOCUMENT)[0] or "application/octet-stream"
    params = { "minimumProductConfidence": 90, "importMode": "Strict" }
 
    with open(DOCUMENT, "rb") as F:
        R = requests.post(FRONTEND + "/api/v1/purchases/import-file",
                          headers=HEADERS, params=params,
                          files={ "file": (name, F, mime) })
 
    if R.status_code not in (200, 400):
        print("request failed (" + str(R.status_code) + ", " + R.reason + ")")
        return
 
    result = R.json()
    if result.get("success"):
        print("imported purchase " + result["procurementName"]
              + " (" + result["procurementId"] + ")")
    else:
        print("import of " + name + " failed")
 
    for line in result.get("logs", []):
        print(" " + line)
 
main()

 

Program content: batch import of a folder

The program uploads all files of a folder in one batch, links the agreements to the purchases of the batch and polls the progress until all files are processed.

import mimetypes
import os
import time
import requests
 
APIKEY = "PUT API KEY HERE"
FRONTEND = "PUT FRONTEND URL HERE"
FOLDER = "PUT FOLDER WITH PURCHASE AND AGREEMENT DOCUMENTS HERE"
 
HEADERS = { "ApiKey": APIKEY }
 
def main():
    data = { "minimumProductConfidence": 90, "importMode": "Strict",
             "relationMode": "GroupRelation" }
    files = []
 
    for name in sorted(os.listdir(FOLDER)):
        path = os.path.join(FOLDER, name)
        if not os.path.isfile(path):
            continue
        index = str(len(files))
        mime = mimetypes.guess_type(path)[0] or "application/octet-stream"
        data["files[" + index + "].id"] = name
        data["files[" + index + "].documentTypeHint"] = "NoHint"
        files.append(("files[" + index + "].file",
                      (name, open(path, "rb"), mime)))
 
    R = requests.post(FRONTEND + "/api/v1/purchases/import-multiple",
                      headers=HEADERS, data=data, files=files)
 
    for entry in files:
        entry[1][1].close()
 
    if not R.ok:
        print("failed to start the import (" + str(R.status_code)
              + ", " + R.reason + ")")
        if R.status_code == 400:
            for line in R.json().get("logs", []):
                print(" " + line)
        return
 
    session_id = R.json()["sessionId"]
 
    while True:
        time.sleep(5)
        P = requests.get(FRONTEND + "/api/v1/purchases/import-progress/"
                         + session_id, headers=HEADERS)
        if not P.ok:
            print("failed to read the import progress ("
                  + str(P.status_code) + ", " + P.reason + ")")
            return
        progress = P.json()
        print(str(progress["completedFiles"]) + " of "
              + str(progress["totalFiles"]) + " files processed")
        if progress["isComplete"]:
            break
 
    for result in progress["results"]:
        status = "imported" if result.get("success") else "failed"
        document = (result.get("procurementName")
                    or result.get("agreementName") or "")
        print(result.get("fileId", "") + ": " + status + " " + document)
        for line in result.get("logs", []):
            print(" " + line)
 
main()