Best practices
New algorithms
Code Examples
Python Example
import requests
# API endpoint with variables
company_id = "your-company-id"
batch_id = "your-batch-id"
url = f"https://saas.haut.ai/v4/companies/{company_id}/batches/{batch_id}/results"
headers = {
"Authorization": f"Bearer {your_token}"
}
response = requests.get(url, headers=headers)
results = response.json()
# Safe parsing: only extract the algorithms you need
# This won't break if new algorithms are added
def extract_needed_algorithms(results):
"""
Extract only the specific algorithms your application uses.
Gracefully handles missing or new algorithms.
"""
extracted_data = {}
# Example: Extract only specific algorithms
algorithms_needed = ['acne_inflammation', 'wrinkles', 'pigmentation']
for algo in algorithms_needed:
if algo in results:
extracted_data[algo] = results[algo]
else:
# Handle missing algorithm gracefully
extracted_data[algo] = None
print(f"Warning: {algo} not found in results")
return extracted_data
# Use the function
my_data = extract_needed_algorithms(results)
# Alternative: Use dict.get() for safe access
acne_data = results.get('acne_inflammation', {})
wrinkles_data = results.get('wrinkles', {})
# Process only what you need, ignore everything else
if acne_data:
severity = acne_data.get('severity')
print(f"Acne severity: {severity}")JavaScript Example
TypeScript Example (with type safety)
Key Takeaways
Last updated
Was this helpful?