Bronto API Best Practices: Preparing for the Unexpected
If you’re using the Bronto API, it’s always a good idea to prepare for scheduled maintenance, heavy load times or even connectivity issues. Otherwise, you could receive a variety of errors, including Server Unavailable or Connection Reset.
Regardless of the reason or the error returned, you should plan for the unexpected.
To do this, you will want to catch any errors and queue them up to be retried at a later time. In other words, you should never assume that every API call will succeed, and you should have a way to store any request that fails, so you do not lose any data due to a temporary issue.
This will probably involve a catch around your API requests and then logic to store those requests and a schedule to send them again.
How you will implement this will depend on what platform you’re using, but try to write your code in such a way that these types of errors are accounted for and added to a queue so they can be tried again when the issue has been resolved.
To help you, here’s some sample pseudo code:
//Makes a call to Bronto API
function sendAPIRequest () {
brontoAPICall();
}
//Logs a failed API call and adds the call back into the queue
function queueFailedAPICall () {
logFailedRequest();
addAPIRequestToQueue();
}
//Adds API request to queue
function addAPIRequestToQueue() {
add failed API request to end of queue;
}
//Gets first API request from queue
function readAPIRequestFromQueue() {
pull first API request from queue;
}
//Process requests in API queue
function doBrontoAPIWork () {
while APIQueue is not empty{
readAPIRequestFromQueue();
try {
sendAPIRequest();
} catch {
queueFailedAPICall ();
wait(10);
}
}
}
To access the Bronto API documentation, click here.
Look for more on API best practices in the near future!
Andrew Kanes
Support Engineer
Bronto Software


Comments
Post new comment