First, let’s verify your API key works by listing your organizations:
cURL
JavaScript
Python
# Set your API keyexport API_KEY="sk_live_YourApiKeyHere"# Test the connectioncurl -X GET "https://answeringagent.com/api/v1/organizations" \ -H "X-API-KEY: $API_KEY" \ -H "Content-Type: application/json"
// Set your API key (use environment variables in production!)const API_KEY = 'sk_live_YourApiKeyHere';const BASE_URL = 'https://answeringagent.com/api/v1';// Test the connectionconst response = await fetch(`${BASE_URL}/organizations`, { headers: { 'X-API-KEY': API_KEY, 'Content-Type': 'application/json' }});const organizations = await response.json();console.log('Your organizations:', organizations);
import requests# Set your API key (use environment variables in production!)API_KEY = 'sk_live_YourApiKeyHere'BASE_URL = 'https://answeringagent.com/api/v1'# Test the connectionresponse = requests.get( f'{BASE_URL}/organizations', headers={ 'X-API-KEY': API_KEY, 'Content-Type': 'application/json' })organizations = response.json()print('Your organizations:', organizations)
Expected Response:
[]
An empty array is perfect! It means your API key is working and you have no organizations yet.
If you get a 401 error, double-check that your API key is correct and you’re using the X-API-KEY header (not Authorization).
Now let’s create an organization for a customer. We’ll create the organization and its owner user in a single API call:
cURL
JavaScript
Python
curl -X POST "https://answeringagent.com/api/v1/organizations" \ -H "X-API-KEY: $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Pizza Palace", "description": "A local pizzeria serving Denver since 1995", "owner": { "external_id": "customer_001", "email": "maria@pizzapalace.com", "name": "Maria Rodriguez" } }'
const orgResponse = await fetch(`${BASE_URL}/organizations`, { method: 'POST', headers: { 'X-API-KEY': API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Pizza Palace', description: 'A local pizzeria serving Denver since 1995', owner: { external_id: 'customer_001', // Your system's ID for this user email: 'maria@pizzapalace.com', name: 'Maria Rodriguez' } })});const { organization, owner } = await orgResponse.json();console.log('Organization created!', organization);console.log('Owner user created!', owner);// Save this for next stepsconst ORG_ID = organization.id;const USER_EXTERNAL_ID = owner.external_id;
org_response = requests.post( f'{BASE_URL}/organizations', headers={ 'X-API-KEY': API_KEY, 'Content-Type': 'application/json' }, json={ 'name': 'Pizza Palace', 'description': 'A local pizzeria serving Denver since 1995', 'owner': { 'external_id': 'customer_001', # Your system's ID for this user 'email': 'maria@pizzapalace.com', 'name': 'Maria Rodriguez' } })data = org_response.json()organization = data['organization']owner = data['owner']print('Organization created!', organization)print('Owner user created!', owner)# Save this for next stepsORG_ID = organization['id']USER_EXTERNAL_ID = owner['external_id']
🎉 Great! You’ve created your first organization with an owner user. Note the organization.id - you’ll need it for the next step.
The external_id is your system’s ID for this user. Use it to link this Answering Agent user to your database. All future API calls can use this ID instead of the internal Answering Agent user ID.
Finally, let’s get an embed token so your customer can access their dashboard:
cURL
JavaScript
Python
# Replace with your user's external_id from step 2USER_EXTERNAL_ID="customer_001"curl -X GET "https://answeringagent.com/api/v1/users/$USER_EXTERNAL_ID/embed-token" \ -H "X-API-KEY: $API_KEY"
const tokenResponse = await fetch( `${BASE_URL}/users/${USER_EXTERNAL_ID}/embed-token`, { headers: { 'X-API-KEY': API_KEY } });const { embed_token } = await tokenResponse.json();console.log('Embed token:', embed_token);// Use this token to embed the dashboard in your appconst embedUrl = `https://answeringagent.com/embed?token=${embed_token}`;console.log('Embed URL:', embedUrl);
token_response = requests.get( f'{BASE_URL}/users/{USER_EXTERNAL_ID}/embed-token', headers={'X-API-KEY': API_KEY})embed_token = token_response.json()['embed_token']print('Embed token:', embed_token)# Use this token to embed the dashboard in your appembed_url = f'https://answeringagent.com/embed?token={embed_token}'print('Embed URL:', embed_url)