INSIGHTCHAIN_API_KEY; the quickstart sets both up. The TypeScript and Python samples run as written once the SDK is installed.
- Push your purchase orders, get stockout risk back
- Check what a tariff costs before you buy
- Act on a recommendation
- Get told when something changes
- Keep your keys healthy
- Find a failed call
- Connect an agent
Push your purchase orders, get stockout risk back
Send the purchase orders you have open and read back which are at risk, and where stock runs out first. Scopes:ingest, read
ingest writes and reads nothing back, so the reads need read on the same key or on a second one.
Step 1. Push the orders. A record is matched on external_id, so sending it again updates it, and an Idempotency-Key makes a retry safe. The sample sends one order that is already late, for an item, a supplier and a location of the sandbox’s demo data. With your own data, push suppliers, items and locations the same way first.
expedite, monitor or on_track).
received, upserted, failed) and the records it refused. A risk row carries purchase_order, risk_score, recommended_action and the factors behind the score. A projection carries on_hand, stockout_in_days and whether inbound stock arrives in time (rescued_by_inbound).
Check what a tariff costs before you buy
Price an import before you place the order: the duty on the tariff line, then the full landed cost. Scopes:read
Step 1. Check the duty on the tariff line from the country you would buy from. Send item_description in place of hs_code when you do not have the code.
effective_rate. The landed cost returns a cost_breakdown (duty, fees, import tax), total_landed_cost and per_unit_landed_cost.
Act on a recommendation
Read what is proposed and why, then approve it or turn it down. Scopes:read, execute, approve
read lists and explains. execute decides a recommendation and proposes an order. approve approves or rejects an order: only an organization admin can put it on a key, and it is held by someone other than the proposer.
Step 1. List what is waiting for a decision, highest priority first.
execute scope and is recorded for the person who created the key. To turn it down, call dismissRecommendation (dismiss_recommendation) the same way.
execute. A second organization admin then approves or rejects it with a key that holds approve: send action: "approve" or "reject" with the order’s id as order_id. The person who proposed an order cannot approve it. A recommendation that is a task for a person is refused here, and the sample prints why.
kind, priority, quantity, the item and locations, and its status. The explanation carries the evidence (headline, drivers, cost and benefit, confidence) and a narrative. A decision returns the recommendation with its new status; a proposed order returns the order with status proposed.
Get told when something changes
Receive a signed request at your own address when something changes, and check that it came from us. Scopes:approve
The key’s creator must be an organization admin. A webhook registered with a test key receives test events only.
Step 1. Register the address that will receive events, and the kinds it wants. The signing secret is in this answer only: store it where your receiver reads it. Set WEBHOOK_URL to a public https address of your own before running the samples of this recipe.
X-InsightChain-Signature-V2 against the raw body before you trust it: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">, keyed with the secret. Refuse a timestamp more than 300 seconds from your clock. The sample runs on its own.
delivery_id is the X-InsightChain-Delivery header your receiver got. A delivery still being retried answers 409 delivery_pending. A sandbox sends test events only, and a test event is sent once, so there the sample finds nothing to send again.
overlap_seconds the old secret keeps signing beside the new one until the window ends: the header carries two v1 values, the new secret’s first, and the check above accepts either. Deploy the new secret to your receiver inside the window.
secret, once. A test returns delivered, the outcome and your receiver’s status. The delivery log returns one row per attempt: event_type, trigger, outcome, status, duration_ms and, for an attempt that will be retried, next_attempt_at.
Keep your keys healthy
See which keys are in use, give each an expiry, and rotate one without downtime. Scopes:keys, read
Only an organization admin can put keys on a key, and the key works while its creator is still an admin. It manages keys of its own environment: a test key the sandbox’s keys, a live key the live ones.
Step 1. List the keys: what each may do, when it was last used and when it expires. A key that has not been used for months is one to revoke.
read as well as keys.
overlap_seconds the old secret stops at once.
expires_at the key answers 401 api_key_expired. Send null for a key that does not expire.
name, key_hint (the prefix and last four characters), scopes, environment, last_used_at (to the minute), expires_at and requests_today. Creating and rotating also return secret, once. Every change is in your audit trail.
Find a failed call
Trace one call from your own logs to ours, and see what failed lately. Scopes:read
Step 1. Send your own id with the call, as X-Request-ID (1 to 128 visible characters). The answer keeps ours in X-Request-ID and echoes yours as X-Client-Request-ID. The sample asks for a recommendation that does not exist, so the call fails.
outcome, status, method, api_key_id, or a time range with since and until.
request_id, your client_request_id, the key, method, the route as a template, status, error_code, latency_ms and whether it came over http or mcp. It never carries a body, a query value or an id from the path. Entries are kept 30 days. Calls made without a valid key are not logged.