Developer ToolsFree generatorPDF, Excel, Word exportInfor LNAll Infor LN and Baan tools

Infor LN ION API OAuth 2.0 REST Call Generator (Python)

This generator writes a Python script that reads an ION API Gateway .ionapi credentials file, gets an OAuth 2.0 access token with the service account keys and calls an Infor LN REST or OData service. It is the smallest working client to test an LN API before you build a real integration.

Fill in

Copy the path of the LN service from the API Gateway documentation for the LN suite in your tenant.

Leave empty unless the API documentation names a company header.

Generated code
Download:

lnapi_call.py

"""Call an Infor LN REST service through ION API Gateway with a .ionapi service account file."""
import json
import sys

import requests

IONAPI_FILE = r"C:\ionapi\LN_backend.ionapi"
SERVICE_PATH = "REPLACE/WITH/PATH/FROM/API/GATEWAY/DOCUMENTATION"
TOP = "10"
ODATA_FILTER = "[$filter (optional)]"
COMPANY_HEADER = "[Company header name (if required)]"
COMPANY = "100"


def load_ionapi(path):
    with open(path, encoding="utf-8") as f:
        cfg = json.load(f)
    for key in ("ti", "ci", "cs", "iu", "pu", "ot", "saak", "sask"):
        if key not in cfg:
            sys.exit("Key '" + key + "' missing: is this a backend service .ionapi file?")
    return cfg


def get_token(cfg):
    token_url = cfg["pu"] + cfg["ot"]
    resp = requests.post(
        token_url,
        data={
            "grant_type": "password",
            "username": cfg["saak"],
            "password": cfg["sask"],
            "client_id": cfg["ci"],
            "client_secret": cfg["cs"],
        },
        timeout=60,
    )
    if resp.status_code != 200:
        sys.exit("Token request failed: " + str(resp.status_code) + " " + resp.text)
    return resp.json()["access_token"]


def call_ln(cfg, token):
    url = cfg["iu"].rstrip("/") + "/" + cfg["ti"] + "/" + SERVICE_PATH.lstrip("/")
    headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
    if COMPANY_HEADER:
        headers[COMPANY_HEADER] = COMPANY
    params = {"$top": TOP}
    if ODATA_FILTER:
        params["$filter"] = ODATA_FILTER
    resp = requests.get(url, headers=headers, params=params, timeout=120)
    if resp.status_code == 401:
        sys.exit("401: token rejected. Check the service account and the .ionapi file.")
    if resp.status_code == 404:
        sys.exit("404: path not found. Check SERVICE_PATH, service activation and entitlement.")
    if resp.status_code == 503:
        sys.exit("503: service unavailable. Check that the LN service is activated and running.")
    resp.raise_for_status()
    return resp.json()


if __name__ == "__main__":
    config = load_ionapi(IONAPI_FILE)
    access_token = get_token(config)
    result = call_ln(config, access_token)
    print(json.dumps(result, indent=2))

Install and run

pip install requests
python lnapi_call.py

The script uses the .ionapi keys ti (tenant), ci and cs (client id and secret), iu (ION API base URL), pu and ot (token endpoint = pu + ot) and saak and sask (service account keys), with the password grant that backend service credentials use. Do not hard-code the LN path: copy it from the API Gateway documentation for the LN suite. Check that LN REST services are available for your LN release and deployment; the LN REST API guides on docs.infor.com are published for recent LN releases. Never commit the .ionapi file to source control; on-prem gateways with internal certificates need requests' verify parameter pointed at your CA bundle, not disabled.

Get your first LN API call working

Send us the error you get (with secrets removed) and your LN and Infor OS versions, and we will tell you which setup step is missing.

Optional. The tool and every export work without this. No spam.

Was this tool useful?

How to use it

Register a backend service authorized app for your integration in ION API Gateway, create a service account for it and download the .ionapi file. Put the file path into the generator, copy the LN service path from the API Gateway documentation for the LN suite, set $top and an optional $filter, and add a company header only if the API documentation names one. Run the script: it checks that the file has the keys it needs, requests a token, calls the service and prints the JSON. Start with $top of 10 so a wrong filter does not pull a large table.

The ION API flow

A .ionapi file is JSON. The token endpoint is pu plus ot. For a backend service file, the client posts grant_type password with saak as username, sask as password and ci and cs as the client credentials, and receives a bearer token. Every API call then goes to iu, the tenant ti and the service path, with the token in the Authorization header. ION API Gateway checks the token and routes the call to LN. Tokens expire, so a long-running integration should cache the token and request a new one when a call returns 401, not request one per call.

  • Token URL: pu + ot
  • API URL: iu / ti / service path
  • Service account keys: saak and sask

Admin steps before the first call

The LN REST API administration guide describes the setup in this order: request access to the LN APIs for your environment, activate the LN services you need, register the authorized app in ION API Gateway, and test the call with a tool such as Postman before writing code. Most failures on the first run come from skipping one of these. A 404 usually means the path is wrong or the service is not activated or entitled; a 503 points to a service that is not activated or not running; a 401 means the token or service account is wrong.

Version notes

LN REST API guides on docs.infor.com are published for recent LN releases, so check whether your on-prem LN 10.x release and Infor OS version include the REST services you want before planning around them. Older on-prem installations may only have BODs through ION and AFS or BOI based integration. Paths and the OData version differ by service, which is why the script takes the path you copy from your own gateway documentation instead of a guessed URL pattern.

Frequently Asked Questions

What is inside an .ionapi file?

It is a JSON file with the tenant (ti), client id and secret (ci, cs), the ION API base URL (iu), the identity provider base URL (pu) and its endpoints such as the token endpoint (ot), and for backend service files the service account keys saak and sask. Treat it as a secret.

Where is the Infor ION API documentation for LN services?

In ION API Gateway, each registered API suite has documentation pages listing its endpoints; the LN suite shows the LN services available in your environment. The ION API administration guide in the Infor OS documentation covers authorized apps and service accounts, and the LN REST API administration guide covers the LN side.

Why do I get 401 even with a fresh token?

Check that the token came from the same tenant as the API URL, that the service account is still active, and that the authorized app was not regenerated after you downloaded the file. Regenerating credentials invalidates older .ionapi files, so download a new one and retry.

Can I use this on an on-prem LN installation?

Yes, if your Infor OS on-prem installation runs ION API Gateway and your LN release provides the REST services. The .ionapi file format and token flow are the same; the URLs point to your own servers. Use your internal CA bundle for TLS verification.

If you want your team to ask LN questions through the same API Gateway, with answers from your own on-prem model, we can set that up.

ArchRay builder
Design the on-prem AI stack for Infor LN and Baan: model, GPUs, RAG pipeline, guardrails
See memory, speed and cost as you swap parts, then export the diagram. Free, in your browser.
Open the builder

Keep exploring

Free tools

ERP fixes and how-tos

Guides

Integrations

Software