If GenAcsTok returns stat: "Not_Ok", the most common cause is that the computer you are using is not on the whitelist. Open api.ipify.org on that computer and make sure the number shown is the Primary IP in trade.infinn.in → top-right profile icon → Generate Key (API Key panel). Only then check the API key, secret and code.
The INFINN login page asks for your user ID, password and TOTP (or OTP). After you sign in, it redirects with the one-time code that you exchange at GenAcsTok.
Login URL: https://api.infinn.in/OAuthlogin/investor-entry-level/login?api_key=<API_KEY>&route_to=<ROUTE_TO>, where route_to = sha256(USER_ID + "|" + SECRET_KEY) (API key example IN001_U). WebSocket: wss://api.infinn.in/NorenWSTP/.
The flow in plain words
- Your program opens the INFINN login page with your App Key.
- You sign in exactly as you do on trade.infinn.in.
- INFINN sends the browser to your Redirect URL with a one-time
code. - Your program sends the code plus a checksum (SHA-256 of App Key + Secret Code + code) and receives an access token.
- Every later request carries
Authorization: Bearer <token>.
Python and JavaScript
Both programs do the same four steps with plain HTTP. No SDK is needed. For a login with no copy-paste, download infinn_quick_login.py (see Login in 5 minutes).
"""oauth_login.py -- log in with OAuth and get an access token (Python 3.8+).
pip install requests
INFINN_API_KEY=IN001_U INFINN_SECRET_KEY=... INFINN_USER_ID=IN001 python oauth_login.py
"""
import hashlib
import json
import os
import requests
BASE = os.environ.get("INFINN_BASE", "https://api.infinn.in")
API_KEY = os.environ.get("INFINN_API_KEY", "IN001_U")
SECRET_KEY = os.environ["INFINN_SECRET_KEY"] # never hard-code this
UID = os.environ.get("INFINN_USER_ID", "IN001")
OAUTH_URL = "https://api.infinn.in/OAuthlogin/investor-entry-level/login"
# route_to is NOT the API key: sha256(USER_ID + "|" + SECRET_KEY), user ID in capitals.
ROUTE_TO = hashlib.sha256((UID.upper() + "|" + SECRET_KEY).encode("utf-8")).hexdigest()
# 1) Open this URL in a browser. Sign in with user ID, password and TOTP/OTP.
print("Open:", f"{OAUTH_URL}?api_key={API_KEY}&route_to={ROUTE_TO}")
# 2) Copy the value after code= (up to any &) from the redirect URL. It works once and expires within seconds.
code = input("Paste the code: ").strip()
# 3) checksum = SHA-256(api_key + secret_key + code), lower-case hex.
checksum = hashlib.sha256((API_KEY + SECRET_KEY + code).encode("utf-8")).hexdigest()
res = requests.post(BASE + "/NorenWClientAPI/GenAcsTok",
headers={"Content-Type": "text/plain"},
data="jData=" + json.dumps({"code": code, "checksum": checksum}),
timeout=15)
if res.status_code != 200:
raise SystemExit(f"HTTP {res.status_code}")
data = res.json()
if data.get("stat") != "Ok":
raise SystemExit(data.get("emsg", "Login failed: get a fresh code and try again"))
# 4) Use access_token as "Authorization: Bearer <token>" on every call.
# It stays valid until about 4:00 AM IST. (Ignore susertoken.)
token = data["access_token"]
print("Logged in. Token ends with", token[-6:])
limits = requests.post(BASE + "/NorenWClientAPI/Limits",
headers={"Authorization": f"Bearer {token}", "Content-Type": "text/plain"},
data="jData=" + json.dumps({"uid": UID, "actid": UID}),
timeout=15).json()
print("Cash:", limits.get("cash"))// oauth_login.js -- log in with OAuth and get an access token (Node 18+, no packages)
// INFINN_API_KEY=IN001_U INFINN_SECRET_KEY=... INFINN_USER_ID=IN001 node oauth_login.js
const crypto = require('crypto');
const readline = require('readline/promises');
const BASE = process.env.INFINN_BASE || 'https://api.infinn.in';
const API_KEY = process.env.INFINN_API_KEY || 'IN001_U';
const SECRET_KEY = process.env.INFINN_SECRET_KEY; // never hard-code this
const UID = process.env.INFINN_USER_ID || 'IN001';
const OAUTH_URL = 'https://api.infinn.in/OAuthlogin/investor-entry-level/login';
async function main() {
if (!SECRET_KEY) throw new Error('Set INFINN_SECRET_KEY');
// route_to is NOT the API key: sha256(USER_ID + '|' + SECRET_KEY), user ID in capitals.
const ROUTE_TO = crypto.createHash('sha256').update(UID.toUpperCase() + '|' + SECRET_KEY).digest('hex');
// 1) Open this URL in a browser. Sign in with user ID, password and TOTP/OTP.
console.log('Open:', `${OAUTH_URL}?api_key=${API_KEY}&route_to=${ROUTE_TO}`);
// 2) Copy the value after code= (up to any &) from the redirect URL. It works once and expires within seconds.
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const code = (await rl.question('Paste the code: ')).trim();
rl.close();
// 3) checksum = SHA-256(api_key + secret_key + code), lower-case hex.
const checksum = crypto.createHash('sha256').update(API_KEY + SECRET_KEY + code, 'utf8').digest('hex');
const res = await fetch(BASE + '/NorenWClientAPI/GenAcsTok', {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: 'jData=' + JSON.stringify({ code, checksum }),
});
if (res.status !== 200) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
if (data.stat !== 'Ok') throw new Error(data.emsg || 'Login failed: get a fresh code and try again');
// 4) Use access_token as "Authorization: Bearer <token>" on every call.
// It stays valid until about 4:00 AM IST. (Ignore susertoken.)
const token = data.access_token;
console.log('Logged in. Token ends with', token.slice(-6));
const limits = await fetch(BASE + '/NorenWClientAPI/Limits', {
method: 'POST',
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'text/plain' },
body: 'jData=' + JSON.stringify({ uid: UID, actid: UID }),
}).then((r) => r.json());
console.log('Cash:', limits.cash);
}
main().catch((err) => { console.error(err.message); process.exit(1); });Good to know
- The code works once and expires quickly. If the exchange fails, log in again.
- The SDK places orders with an optional
algo_idargument; see SEBI retail algo rules. - The older package
NorenRestApiPy(0.0.22) uses a password-and-vendor-code login. Do not use it for INFINN. - Prefer to do it by hand first? Follow Authentication step by step.