Registry / cms / wpcom
library7.1.1jsnpmunverified

The official JavaScript library for the WordPress.com REST API, version 7.1.1. It provides a comprehensive client for interacting with WordPress.com sites, including posts, media, comments, and user data. Built with modern JavaScript, it ships TypeScript definitions and supports both ESM (ES Modules) and CommonJS. Released actively alongside the WordPress.com platform, it is the recommended client for WordPress.com API integration, offering methods that return Promises and support for OAuth2 authentication. Its key differentiator is direct support and maintenance by Automattic, ensuring compatibility with WordPress.com's REST API endpoints.

npm install wpcom
INSTALL
IMPORT
SIG · WPCOM
W
wpcom
cmsjavascriptv7.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WPCOM
import WPCOM from 'wpcom'
const { WPCOM } = require('wpcom')
WPCOM is a default export; named import will not work.
WPCOM
const WPCOM = require('wpcom').default
const WPCOM = require('wpcom')
In CommonJS, use .default to get the default export, or use import syntax.
Site
import WPCOM from 'wpcom'; const wp = new WPCOM( '<your-token>' ); const site = wp.site( 'site-id' );
import { Site } from 'wpcom'
Site is not a named export; it is created via the WPCOM instance.
Request
import WPCOM from 'wpcom'; const req = WPCOM.Request;
const { Request } = require('wpcom')
Request is a static property of the default export.

Initializes a WPCOM client, fetches site info, and creates a new post using async/await.

import WPCOM from 'wpcom'; // Initialize with a token (replace with real token in production) const wp = new WPCOM( process.env.WPCOM_TOKEN ?? '' ); // Get site info async function getSiteInfo() { try { const site = await wp.site( 'en.blog.wordpress.com' ).get(); console.log( site.name ); } catch ( error ) { console.error( error ); } } getSiteInfo(); // Create a post async function createPost() { try { const post = await wp.site( 'my-site.wordpress.com' ).post().add( { title: 'Hello World', content: 'This is my first post via API.' } ); console.log( post.ID ); } catch ( error ) { console.error( error ); } } createPost();
Debug
Known issues
breakingThe library version 5.x dropped support for callbacks; all methods now return Promises.
fix
Use .then() or async/await instead of callback functions.
affects: >=5.0.0
breakingVersion 7.x switched to ESM default export. CommonJS users must use require('wpcom').default.
fix
Use import WPCOM from 'wpcom' or const WPCOM = require('wpcom').default.
affects: >=7.0.0
deprecatedConstructor accepting a token directly is deprecated in favor of OAuth2 token flow.
fix
Use new WPCOM({ token: '...' }) or upgrade to OAuth2 client.
affects: >=6.0.0
gotchaThe library requires a valid WordPress.com OAuth2 token; anonymous access is not supported.
fix
Generate an API token from your WordPress.com developer settings.
affects: all
gotchaMethods like .site() return a Site instance, but do not fetch data until .get() is called.
fix
Always call .get() or .add() etc. to execute the request.
affects: all
Errors
Common errors & fixes
TypeError: WPCOM is not a constructor
Using CommonJS require without .default in version 7+
fix
Use import WPCOM from 'wpcom' or const WPCOM = require('wpcom').default;
Error: Callback expected. Use promise instead.
Using a callback function with a method that returns a Promise in version 5+
fix
Use .then() or async/await instead of passing a callback.
401 Unauthorized
Invalid or expired OAuth2 token
fix
Generate a new token from your WordPress.com developer settings and ensure it's passed correctly.
Upgrade
Version history
7.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
52 hits · last 30 days
node
44
OpenAI (training)
1
Resources
packagewpcom
wpcom — npm install wpcom · libregistry