// Edit a post on a siteimport wpcomFactory from 'wpcom';import wpcomXhrRequest from 'wpcom-xhr-request';const wpcom = wpcomFactory( '<your-token>', wpcomXhrRequest );const 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 siteimport wpcomFactory from 'wpcom';import wpcomXhrRequest from 'wpcom-xhr-request';const wpcom = wpcomFactory( wpcomXhrRequest );const 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>: