Multiple questions about a change to API2 I saw today...

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?

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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 :)

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.