Blipfoto API

Responses

Each response can be in one of three formats; XML, JSON or a serialised PHP object (the default format is XML). For either format, the response is divided into two sections, error and data.

The error section contains information about any error that occurred while trying to process the request.

The data section contains information from a successful response.

For version 2 and above, a version section is also returned containing the version number used in the request.

Format differences

While responses can be sent in different formats, the formats themselves handle datatypes differently. For clarity:

  • Unique identifiers such as entry_id may be numeric, but should always treated as strings.
  • JSON and PHP responses can handle indexed (sequential) arrays. XML has no equivalent; instead each item in the array is represented with a child item node.

    JSON:

    {
    "data":[
    	"one",
    	"two",
    	"three"
    	]
    }

    XML equivalent:

    <data>
    	<item>one</item>
    	<item>two</item>
    	<item>three</item>
    </data>
  • PHP responses can handle associative arrays. JSON responses convert these to object literals, while XML responses use the array key as the node name.

    JSON equivalent:

    {
    "data":{
    	"name":"Homer",
    	"location":"Springfield"
    	}
    }

    XML equivalent:

    <data>
    	<name>Homer</name>
    	<location>Springfield</location>
    </data>

XML Response

A successful XML response will take the following shape:

<?xml version="1.0" encoding="UTF-8"?>
<blipapi>
	<version>2</version>
	<request_id>23</request_id>
	<error></error>
	<data>
		...
	</data>
</blipapi>

JSON Response

A successful JSON response will take the following shape:

{
"version":2,
"request_id":23,
"error":null,
"data":...
}

An unsuccessful response looks like this:

{
"version":2,
"request_id":23,
"error":{
	"code":201,
	"message":"You have not specified a journal entry date."
	},
"data":null
}

If you are consuming a JSON response using client-side JavaScript, you may want to provide a value to the callback request parameter. Doing so will wrap the response in the callback (this is known as JSON-P). For example, the following request:

http://api.blipfoto.com/get/exampleResource/?api_key=4c297fc904&format=JSON&callback=foo

causes the response to be wrapped as follows:

foo && foo({
	"version":2,
	"error":{},
	"data":...
	});

Providing the foo() function is defined on the client, it will be called with the JSON object as its argument, meaning no extra parsing is required.

PHP Response

If you specify the PHP format, the response will be returned as a serialized PHP array. This is useful when accessing the API from a PHP-based application, as you simply need to call the native unserialize() function on the response. Doing so will return an associative array containing the version, response_id, error and data properties.

HTTP status codes

Note this behaviour is deprecated, meaning all responses return 200 OK regardless of any underlying API error code.

When checking a response for errors, you can inspect the response's header for its HTTP status code. A successful request will always return 200 OK, whereas an unsuccessful request returns a failure code (401 Unauthorized, 403 Forbidden etc). You can then inspect the API-specific error code that has been returned in the response.