// Edit a post on a sitevar wpcom = require( 'wpcom' )( '<your-token>' );var blog = wpcom.site( 'your-blog.wordpress.com' );blog.post( { slug: 'a-post-slug' } ).update( data ) .then( res => { ... } ) .catch( err => { ... } );
You can omit the API token for operations that don't require permissions:
// List the last 8 posts on a sitevar wpcom = require( 'wpcom' )();var blog = wpcom.site( 'your-blog.wordpress.com' );blog.postsList( { number: 8 } ) .then( list => { ... } ) .catch( error => { ... } );
More pre-made examples are in the examples/ directory.
Test
The token and site vars must be given to testing scripts either using
TOKEN and SITE environment vars respectively or through of a
config.json file into test/ folder like bellow:
{ "site": "<site-id>", "token": "<token>"}
Run tests:
$ make test-all
Also tests can be filtered using make test FILTER=<filter>: