By bob1959
A little background:
When creating droplets, I had been building a PHP array with the following code:
$data = array( “name” => $name, “region” => “nyc3”, “size” => “512mb”, “image” => [xxxxxxxx], “ssh_keys” => [xxxxxx] );
Today that totally crapped out. I was able to finally figure out I had to change this line:
“image” => [xxxxxxxx],
to this:
“image” => “xxxxxxxx”,
After this API change, I’m now doing some error checking in the API’s response by looking for the word “message” (I noticed it appears in error messages from creating droplets as well as from attempting to delete non-existent DNS records – and doesn’t appear in any replies I’ve seen when all is well).
Does that word (“message”) only appear in error messages from the API? Is there a better way to check the API’s response for an error message?
Also, is there any place to monitor for changes like these so we know to go check our code for compliance with the change?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sorry about the inconvenience! Normally, changes to the API are announced in the changelog section of the Developer’s site. This was changed as the result of a bug fix. That behavior was never documented or intended.
When checking for error messages, the best thing to do is look at the HTTP status returned with the response for anything in the 400 or 500 range. Successful requests will return something in the 200 range.
All error messages should be valid json in the form of:
{
"id": "forbidden",
"message": "You do not have access for the attempted action."
}
That message would have return a 403 status code.
Thanks again, asb (this isn’t the first time you’ve answered a question for me).
Checking the HTTP status works perfectly – and thanks for the link to the changelog too :)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.