Skip to main content

Does anyone know what’s happening here?

 

I’m calling the /api/campaign-recipient-estimations/<campaign_id> endpoint, i first get all the user campaigns and then cycle through each campaign to get it’s recipient estimation, i’m getting this weird error

{
"errors": "
{
"id": "6f3bd40f-6a67-463e-a28c-02061e0e0027",
"status": 404,
"code": "error",
"title": "A server error occurred.",
"detail": "No results or results were out of date. Schedule a new estimation or wait for your estimation to complete.",
"source": {
"pointer": "/data/"
}
}
]
}

It doesn’t happen always though, for most campaigns it works fine, but then fails randomly

 

This is my axios request config for getting recipient estimation

{
method: 'GET',
url: `https://a.klaviyo.com/api/campaign-recipient-estimations/${args.campaignId}`,
headers: {
accept: 'application/json',
'content-type': 'application/json',
revision: constant.KLAVIYO_API_VERSION,
Authorization: `Klaviyo-API-Key ${args.apiKey}`,
},
}

 

Hi @airboxr

Try calling the create campaign estimation job API for the cases where the estimate fails. It's possible the estimate is out of date. Running this job asynchronously updates the estimation. Because this job executes asynchronously, it may not be done right away and there is an endpoint to get the status of the job.

To summarize:
1. create a job to update the campaign recipient estimation
2. get status of job
3. when status is "complete", re-fetch the estimation amount for the campaign

# API endpoint for creating a job to update the estimation
# docs: https://developers.klaviyo.com/en/reference/create_campaign_recipient_estimation_job
POST https://a.klaviyo.com/api/campaign-recipient-estimation-jobs/


# API endpoint to get the status of the job
# docs: https://developers.klaviyo.com/en/reference/get_campaign_recipient_estimation_job
GET https://a.klaviyo.com/api/campaign-recipient-estimation-jobs/{id}/

Once the status of the job is "complete" then he can retry fetching the updated campaign estimation. 

~Chloe


Reply