Files
f3nris 6343a0c952 feat(ipinfo): support the Lite API for free/Lite plan tokens (v1.1.0)
The integration only exposed the Core API (/lookup/*), which returns 403
for accounts on the free/Lite plan — including the instance Test button.

Add the Lite endpoints: lite_lookup_ip (GET /lite/{ip}), lite_lookup_me
(GET /lite/me) and lite_batch (POST /batch/lite, code-first because the
endpoint takes a raw JSON array; chunked at the documented 1000-IP cap).

Point test_connection at /lite/me: every plan can reach it, so the token
check now succeeds on Lite-only accounts while still validating Core ones.
Core commands keep their paths and state the plan requirement up front.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 21:01:43 +02:00

49 lines
1.5 KiB
Python

import json, os, sys, urllib.request, urllib.parse, urllib.error
SECRETS = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
INPUTS = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
BASE = SECRETS.get("base_url", "https://api.ipinfo.io").rstrip("/")
# IPinfo caps a single Lite batch call at 1000 addresses.
CHUNK = 1000
def post_chunk(url, ips):
# POST /batch/lite expects a raw JSON array of IPs, not an object.
data = json.dumps(ips).encode("utf-8")
headers = {"Content-Type": "application/json", "Accept": "application/json"}
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
with urllib.request.urlopen(req, timeout=30) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def main():
token = SECRETS.get("token", "")
seen = set()
ips = []
for x in str(INPUTS.get("ips", "")).split(","):
x = x.strip()
if x and x not in seen:
seen.add(x)
ips.append(x)
if not ips:
print(json.dumps({"error": "ips is required"}))
sys.exit(1)
url = BASE + "/batch/lite?" + urllib.parse.urlencode({"token": token})
result = {}
for i in range(0, len(ips), CHUNK):
result.update(post_chunk(url, ips[i:i + CHUNK]))
print(json.dumps(result))
try:
main()
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)