Code examples
Pick a language, add your credentials, and make the example yours. Every snippet below is self-contained and ready to copy into your own project.
Start with authentication
Section titled “Start with authentication”-
Create an API key in Account → Partnerships.
-
Add it to your terminal session:
Terminal window export IA_API_KEY="your_api_key" -
Choose an example below. Each one connects to the production Infinite Audience API by default.
#!/usr/bin/env bash# Example 1 — auth-token-exchange. Free, no billing risk.## Exchange an API key for a 1-hour access token, then use it. There is no# refresh token — when it's close to expiring, re-run this same exchange.set -euo pipefail
: "${IA_API_KEY:?Set IA_API_KEY in your terminal before running this example}"IA_BASE_URL="${IA_BASE_URL:-https://api.infiniteaudience.ai}"
echo "Exchanging API key for an access token..." >&2TOKEN_RESPONSE=$(curl -sf -X POST "$IA_BASE_URL/v1/auth/token" \ -H "Content-Type: application/json" \ -d "{\"api_key\": \"$IA_API_KEY\"}")
ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"access_token":"[^"]*"' | cut -d'"' -f4)EXPIRES_IN=$(echo "$TOKEN_RESPONSE" | grep -o '"expires_in":[0-9]*' | cut -d: -f2)echo "Got a token, expires in ${EXPIRES_IN}s (always 3600 — no refresh token, re-exchange instead)." >&2
echo "Using it against GET /v1/catalog/fields..." >&2curl -sf "$IA_BASE_URL/v1/catalog/fields" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ | head -c 500echoTypeScript
Section titled “TypeScript”/** * Example 1 — auth-token-exchange. Free, no billing risk. * * Exchange an API key for a 1-hour access token, then use it. */import { env, exit } from 'node:process';
const apiKey = env.IA_API_KEY;const baseUrl = env.IA_BASE_URL ?? 'https://api.infiniteaudience.ai';
if (!apiKey) { throw new Error('Set IA_API_KEY in your terminal before running this example.');}
async function main() { console.log('Exchanging API key for an access token...'); const tokenResponse = await fetch(`${baseUrl}/v1/auth/token`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ api_key: apiKey }), });
if (!tokenResponse.ok) { throw new Error(`Token exchange failed (${tokenResponse.status}).`); }
const { access_token: accessToken, expires_in: expiresIn } = await tokenResponse.json() as { access_token: string; expires_in: number; }; console.log(`Access token ready. It expires in ${expiresIn} seconds.`);
console.log('Using it against GET /v1/catalog/fields...'); const fieldsResponse = await fetch(`${baseUrl}/v1/catalog/fields`, { headers: { Authorization: `Bearer ${accessToken}` }, });
if (!fieldsResponse.ok) { throw new Error(`Catalog request failed (${fieldsResponse.status}).`); }
const fields = await fieldsResponse.json() as { fields?: unknown[] }; console.log(`Catalog has ${Array.isArray(fields.fields) ? fields.fields.length : '?'} fields.`);}
main().catch((err) => { console.error(err); exit(1);});Python
Section titled “Python”"""Example 1 -- auth-token-exchange. Free, no billing risk.
Exchange an API key for a 1-hour access token, then use it."""
import jsonimport osfrom urllib.request import Request, urlopen
API_KEY = os.getenv("IA_API_KEY")BASE_URL = os.getenv("IA_BASE_URL", "https://api.infiniteaudience.ai")
if not API_KEY: raise RuntimeError("Set IA_API_KEY in your terminal before running this example.")
def main() -> None: print("Exchanging API key for an access token...") token_request = Request( f"{BASE_URL}/v1/auth/token", data=json.dumps({"api_key": API_KEY}).encode(), headers={"Content-Type": "application/json"}, method="POST", ) with urlopen(token_request) as response: token_response = json.load(response)
access_token = token_response["access_token"] print(f"Access token ready. It expires in {token_response['expires_in']} seconds.")
print("Using it against GET /v1/catalog/fields...") fields_request = Request( f"{BASE_URL}/v1/catalog/fields", headers={"Authorization": f"Bearer {access_token}"}, ) with urlopen(fields_request) as response: fields = json.load(response)
print(f"Catalog has {len(fields.get('fields', []))} fields.")
if __name__ == "__main__": main()More ready-to-run flows
Section titled “More ready-to-run flows”Ready for the next workflow? Continue with real-time enrichment, file enrichment, webhooks, or explore the full API reference.
