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.
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.
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.
Related Tools
Infor LN Inbound Process.SalesOrder BOD XML Template
Generate an OAGIS ProcessSalesOrder BOD skeleton with ApplicationArea, ActionCriteria, a sales order header and order lines for testing LN inbound orders.
Developer ToolsInfor LN AFS (stpapi) Session Automation Script Generator
Generate Application Function Server (AFS) functions that insert, update and delete records through a standard LN session without its user interface.
Infor LN & BaanInfor LN Integration Methods Reference
A comparison table of the main ways to move data in and out of Infor LN, with typical use, direction and cautions.
More Developer Tools tools
See all- Infor LN DAL and User Exit Hook Functions Reference
- Infor LN DAL Script Template Generator
- Infor LN User Exit (UE) DLL Template Generator
- Infor LN Report Script Template Generator
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
Keep exploring
Free tools
- Infor ION API Gateway OAuth Token Request Generator (.ionapi)Turn the values in a downloaded .ionapi file into code that requests a token from the Infor authorization server, calls the ION API Gateway and revokes the token.
- Infor LN Report Script Template GeneratorGenerate a 4GL report script for an LN report with program sections, layout sections, a suppress condition and a running total.
- Infor LN DAL Script Template GeneratorGenerate a Data Access Layer (DAL) script skeleton for an LN table with object hooks, a field check hook, a mandatory hook and error message handling.
ERP fixes and how-tos
- Infor LN REST API: documentation, administration and a first callWhere Infor LN REST API documentation lives, how to enable and administer API access through ION API, and how to make a first authenticated call.
- Infor LN integration document types and integration rules with IONHow integration document types and rules work in Infor LN with ION and BODs: what they define, how mapping is set up, and where to debug.
- How to Create an .ionapi File and Service Account in Infor OSStep by step: register a Backend Service in ION API, create a service account, download the .ionapi file, and use it to get an OAuth token from Infor OS.
Guides
- Infor LN ION API Integration GuideInfor ION API guide for LN: when to use the ION API gateway, BOD messaging or file-based exchange, how OAuth 2.0 access works, and how to secure calls.
- Salesforce to Infor LN Data Integration GuideInfor Salesforce integration for Infor LN: sync customers, orders and pricing between Salesforce CRM and LN using ION, BODs and REST APIs. SyteLine covered too.
- AI Integration with Infor LN and Baan: A Technical GuideIntegrate AI with Infor LN or Baan: ION API patterns, business object documents, session versus web service access, and where AI agents should not write.
Integrations
- How to add AI agents to Infor LNHow to add AI agents to Infor LN: a tool layer over ION API and BODs, read-only reporting first, approval before writes, and fully on-prem model hosting.
- How to add WhatsApp to Infor LNHow to connect WhatsApp to Infor LN: ION BODs and APIs, template messages, opt-in rules, supplier confirmations and order status, including on-prem LN setups.