Platform Updates: Batching Calls, Privacy Settings, and IDs

We’ve made a few more updates to our APIs recently that we wanted to share with you.

The biggest update is a new query parameter that’s now available on all endpoints. The new parameter allows you to batch certain calls together, so you only need to make one request to get related data instead of two or three.

Since we released our APIs, we’d always return a list of related endpoints in the “meta” response with a series of links:

"meta": {
        "links": {
            "self": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238",
            "help": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238/help",
            "site": "https://public-api.wordpress.com/rest/v1/sites/3584907",
            "replies": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238/replies/",
            "likes": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238/likes/"
},

Now, by passing ?meta=site, you can automatically get the data from the above endpoints in the original response. Let’s take a look at an example.

Say you’re loading a specific post but you want to know the name and description of the site the post was on. You can do this by making a call to: https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/posts/21238/?meta=site.

Which will give you a response like the following:

"meta": {
        "links": {
            "self": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238",
            "help": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238/help",
            "site": "https://public-api.wordpress.com/rest/v1/sites/3584907",
            "replies": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238/replies/",
            "likes": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/21238/likes/"
        },
        "data": {
            "site": {
                "ID": 3584907,
                "name": "WordPress.com News",
                "description": "The latest news on WordPress.com and the WordPress community.",
                "URL": "http://en.blog.wordpress.com",
                "jetpack": false,
                "subscribers_count": 8396934,
                "meta": {
                    "links": {
                        "self": "https://public-api.wordpress.com/rest/v1/sites/3584907",
                        "help": "https://public-api.wordpress.com/rest/v1/sites/3584907/help",
                        "posts": "https://public-api.wordpress.com/rest/v1/sites/3584907/posts/",
                        "comments": "https://public-api.wordpress.com/rest/v1/sites/3584907/comments/"
                    }
                },
                "is_private": false
            }
}

You can also pass multiple values in the meta query string. If you wanted the site endpoint and a list of likes for a post you can just pass "site,likes".

Two other updates we made are new responses:

  • We now include the value of privacy setting in the site information endpoint. A boolean value will be included as is_private.
  • We now include a global_ID response for all posts. This is a unique ID that you can use to identify posts if you are loading posts from multiple blogs in your application.

We hope you enjoy these updates. We’ll be making more improvements soon!