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

June 30, 2015 527 views

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?

2 Answers

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

Have another answer? Share your knowledge.