Getting Started with 
WordPress JSON REST API 
Takuro Hishikawa 
concrete5 Japan Inc. 
! 
An author of Really Simple CSV Importer plugin 
(20,000+ download! Thanks!)
What Is the JSON REST 
API? 
• Started as GSOC project 
• Now provided as plugin 
• Planned merge into core at future release
“Access your WordPress site’s data through 
an easy-to-use HTTP REST API.” 
–http://wp-api.org/
“JSON is a data format based on 
Javascript’s representation of objects, but 
it’s widely used because it can be easily 
represented in almost every programming 
language.” 
–Ryan McCue 
http://wptavern.com/ryan-mccue-on-creating-the-json-rest-api-for-wordpress
Resources 
• Posts (Create/Retrieve/Edit/Delete) 
• Meta (Create/Retrieve/Edit/Delete) 
• Media (Create/Get) 
• Users (Create/Retrieve/Edit/Delete) 
• Taxonomy/Terms (Retrieve)
Building App Example 
• Framework = concrete5 
• Library = Zend_Oauth, Zend_Http_Client
Demo 
• Get posts from WordPress 
• Get the specific post from WordPress 
• Insert a new post to WordPress
Step by step
Set up the plugin 
• https://github.com/WP-API/WP-API/ 
• https://github.com/WP-API/OAuth1/
Get Access Token from 
WordPress 
• Blog post (Japanese) 
• http://notnil-creative.com/blog/archives/ 
3301
Send HTTP Request to 
WordPress 
$client = Loader::helper('wp_api','rest_wordpress')->getClient(); 
$client->setUri($wp_rest_api_url.’/posts'); 
$client->setMethod(Zend_Http_Client::GET); 
$client->setParameterGet('filter[posts_per_page]',$num); 
$client->setParameterGet(‘filter[cat]',$cat); 
$client->setParameterGet('filter[orderby]','title'); 
$client->setParameterGet(‘filter[order]','ASC'); 
$response = $client->request();
Send HTTP Request to 
WordPress 
$client = Loader::helper('wp_api','rest_wordpress')->getClient(); 
$client->setUri($wp_rest_api_url.'/posts'); 
$client->setMethod(Zend_Http_Client::POST); 
$data = array( 
'title' => $this->post('post_title'), 
'content_raw' => $this->post('post_body'), 
'status' => 'publish' 
); 
$client->setRawData(Loader::helper('json')->encode($data),'application/ 
json'); 
$res = $client->request();
Easy, right?
• As you can see, working with JSON REST API requires 
little knowledge of OAuth and building HTTP 
Request… 
• Use library! 
JSON is a popular object type, OAuth is also popular 
• Some issues… 
https://github.com/WP-API/OAuth1/issues/37 
https://github.com/WP-API/OAuth1/issues/34
Thanks! 
Follow me! 
! 
Twitter: @HissyNC 
GitHub: @hissy

Getting Started with WordPress JSON REST API

  • 1.
    Getting Started with WordPress JSON REST API Takuro Hishikawa concrete5 Japan Inc. ! An author of Really Simple CSV Importer plugin (20,000+ download! Thanks!)
  • 2.
    What Is theJSON REST API? • Started as GSOC project • Now provided as plugin • Planned merge into core at future release
  • 3.
    “Access your WordPresssite’s data through an easy-to-use HTTP REST API.” –http://wp-api.org/
  • 4.
    “JSON is adata format based on Javascript’s representation of objects, but it’s widely used because it can be easily represented in almost every programming language.” –Ryan McCue http://wptavern.com/ryan-mccue-on-creating-the-json-rest-api-for-wordpress
  • 5.
    Resources • Posts(Create/Retrieve/Edit/Delete) • Meta (Create/Retrieve/Edit/Delete) • Media (Create/Get) • Users (Create/Retrieve/Edit/Delete) • Taxonomy/Terms (Retrieve)
  • 6.
    Building App Example • Framework = concrete5 • Library = Zend_Oauth, Zend_Http_Client
  • 7.
    Demo • Getposts from WordPress • Get the specific post from WordPress • Insert a new post to WordPress
  • 8.
  • 9.
    Set up theplugin • https://github.com/WP-API/WP-API/ • https://github.com/WP-API/OAuth1/
  • 10.
    Get Access Tokenfrom WordPress • Blog post (Japanese) • http://notnil-creative.com/blog/archives/ 3301
  • 11.
    Send HTTP Requestto WordPress $client = Loader::helper('wp_api','rest_wordpress')->getClient(); $client->setUri($wp_rest_api_url.’/posts'); $client->setMethod(Zend_Http_Client::GET); $client->setParameterGet('filter[posts_per_page]',$num); $client->setParameterGet(‘filter[cat]',$cat); $client->setParameterGet('filter[orderby]','title'); $client->setParameterGet(‘filter[order]','ASC'); $response = $client->request();
  • 12.
    Send HTTP Requestto WordPress $client = Loader::helper('wp_api','rest_wordpress')->getClient(); $client->setUri($wp_rest_api_url.'/posts'); $client->setMethod(Zend_Http_Client::POST); $data = array( 'title' => $this->post('post_title'), 'content_raw' => $this->post('post_body'), 'status' => 'publish' ); $client->setRawData(Loader::helper('json')->encode($data),'application/ json'); $res = $client->request();
  • 13.
  • 14.
    • As youcan see, working with JSON REST API requires little knowledge of OAuth and building HTTP Request… • Use library! JSON is a popular object type, OAuth is also popular • Some issues… https://github.com/WP-API/OAuth1/issues/37 https://github.com/WP-API/OAuth1/issues/34
  • 15.
    Thanks! Follow me! ! Twitter: @HissyNC GitHub: @hissy