This guide explains how to handle errors in the Cloutfit API and provides examples of possible API exceptions.
Cloutfit uses conventional HTTP response codes to indicate the success or failure of an API request. In general:
All error responses include a JSON object with an error message to help you understand what went wrong.
{
"error": {
"code": "error_code",
"message": "A human-readable message providing more details about the error.",
"status": 400
}
}Here are some common error codes you might encounter when using the Cloutfit API:
| Error Code | Status | Description |
|---|---|---|
| authentication_required | 401 | No valid API key provided. |
| invalid_request | 400 | The request was unacceptable, often due to missing a required parameter. |
| not_found | 404 | The requested resource doesn't exist. |
| rate_limit_exceeded | 429 | Too many requests hit the API too quickly. |
| server_error | 500 | Something went wrong on Cloutfit's end. |
We recommend writing code that gracefully handles all possible API exceptions. Here are some examples of how to handle errors in different programming languages:
async function getInfluencer(influencerId) {
try {
const response = await fetch(`https://app.cloutfit.ai/v1/influencers/${influencerId}`, {
headers: {
'Authorization': `Bearer ${API_KEY}`
}
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(`API Error: ${errorData.error.message}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching influencer:', error);
// Handle the error appropriately
}
}Many objects allow you to request additional information as an expanded response by using the expand request parameter. This parameter is available on all API requests, and applies to the response of that request only.
You can expand multiple objects at once by specifying a comma-separated list of objects to expand.
curl https://app.cloutfit.ai/v1/posts/post_1234567890?expand=influencer,products \
-H "Authorization: Bearer YOUR_API_KEY"curl https://app.cloutfit.ai/v1/influencers/non_existent_id \
-H "Authorization: Bearer YOUR_API_KEY"