SDKs & Libraries
This section provides code examples and patterns for working with the Audian API in various programming languages.
API Overview​
The Audian API uses a consistent pattern across all endpoints:
- Base URL:
https://api.audian.com:8443/v2/ - Authentication:
X-Auth-Tokenheader - Request Body: Wrapped in
{"data": {...}} - HTTP Methods: GET (list/retrieve), PUT (create), POST (update), DELETE (remove)
Quick Start Examples​
Bash/cURL​
# Authenticate and get token
RESPONSE=$(curl -s -X PUT https://api.audian.com:8443/v2/api_auth \
-H "Content-Type: application/json" \
-d '{"data": {"api_key": "YOUR_API_KEY"}}')
AUTH_TOKEN=$(echo $RESPONSE | jq -r '.auth_token')
ACCOUNT_ID=$(echo $RESPONSE | jq -r '.data.account_id')
# List users
curl -X GET "https://api.audian.com:8443/v2/accounts/${ACCOUNT_ID}/users?paginate=false" \
-H "X-Auth-Token: ${AUTH_TOKEN}" \
-H "Accept: application/json"
Python​
import requests
# Authenticate
auth_response = requests.put(
'https://api.audian.com:8443/v2/api_auth',
json={'data': {'api_key': 'YOUR_API_KEY'}}
)
auth_data = auth_response.json()
auth_token = auth_data['auth_token']
account_id = auth_data['data']['account_id']
# List users
headers = {
'X-Auth-Token': auth_token,
'Accept': 'application/json'
}
users_response = requests.get(
f'https://api.audian.com:8443/v2/accounts/{account_id}/users?paginate=false',
headers=headers
)
users = users_response.json()['data']
JavaScript/Node.js​
const axios = require('axios');
async function main() {
// Authenticate
const authResponse = await axios.put(
'https://api.audian.com:8443/v2/api_auth',
{ data: { api_key: 'YOUR_API_KEY' } }
);
const authToken = authResponse.data.auth_token;
const accountId = authResponse.data.data.account_id;
// List users
const usersResponse = await axios.get(
`https://api.audian.com:8443/v2/accounts/${accountId}/users?paginate=false`,
{
headers: {
'X-Auth-Token': authToken,
'Accept': 'application/json'
}
}
);
const users = usersResponse.data.data;
console.log(users);
}
main();
Go​
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
// Authenticate
authBody := map[string]interface{}{
"data": map[string]string{
"api_key": "YOUR_API_KEY",
},
}
authJSON, _ := json.Marshal(authBody)
authResp, _ := http.Post(
"https://api.audian.com:8443/v2/api_auth",
"application/json",
bytes.NewBuffer(authJSON),
)
defer authResp.Body.Close()
var authData map[string]interface{}
json.NewDecoder(authResp.Body).Decode(&authData)
authToken := authData["auth_token"].(string)
accountId := authData["data"].(map[string]interface{})["account_id"].(string)
// List users
req, _ := http.NewRequest(
"GET",
fmt.Sprintf("https://api.audian.com:8443/v2/accounts/%s/users?paginate=false", accountId),
nil,
)
req.Header.Set("X-Auth-Token", authToken)
req.Header.Set("Accept", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
Common Patterns​
Error Handling​
response = requests.get(url, headers=headers)
data = response.json()
if data.get('status') == 'error':
error_code = data.get('error')
message = data.get('message')
print(f"Error {error_code}: {message}")
else:
# Process successful response
result = data['data']
Pagination​
# Get all results without pagination
response = requests.get(
f'{base_url}/users?paginate=false',
headers=headers
)
# Or paginate manually
response = requests.get(
f'{base_url}/users?page_size=50',
headers=headers
)
Creating Resources​
# Use PUT for creating new resources
response = requests.put(
f'{base_url}/users',
headers=headers,
json={
'data': {
'first_name': 'Jane',
'last_name': 'Smith',
'email': 'jane@example.com'
}
}
)
Updating Resources​
# Use POST for updating existing resources
response = requests.post(
f'{base_url}/users/{user_id}',
headers=headers,
json={
'data': {
'first_name': 'Jane',
'last_name': 'Smith-Jones'
}
}
)
API Response Format​
All successful responses follow this structure:
{
"auth_token": "eyJhbGciOiJSUzI1...",
"data": { ... },
"request_id": "req_xyz789",
"status": "success"
}
Error responses:
{
"auth_token": "eyJhbGciOiJSUzI1...",
"data": {
"message": "error description"
},
"error": "400",
"message": "bad_request",
"status": "error"
}
Topics​
- Python Examples - Python code samples
- JavaScript Examples - Node.js code samples
- Go Examples - Go code samples