{"id":49761,"library":"wpcom","title":"WordPress.com REST API JavaScript Library","description":"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.","status":"active","version":"7.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/Automattic/wp-calypso","tags":["javascript","wordpress","wordpress.com","browser","rest","api","library","typescript"],"install":[{"cmd":"npm install wpcom","lang":"bash","label":"npm"},{"cmd":"yarn add wpcom","lang":"bash","label":"yarn"},{"cmd":"pnpm add wpcom","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"WPCOM is a default export; named import will not work.","wrong":"const { WPCOM } = require('wpcom')","symbol":"WPCOM","correct":"import WPCOM from 'wpcom'"},{"note":"In CommonJS, use .default to get the default export, or use import syntax.","wrong":"const WPCOM = require('wpcom')","symbol":"WPCOM","correct":"const WPCOM = require('wpcom').default"},{"note":"Site is not a named export; it is created via the WPCOM instance.","wrong":"import { Site } from 'wpcom'","symbol":"Site","correct":"import WPCOM from 'wpcom';\nconst wp = new WPCOM( '<your-token>' );\nconst site = wp.site( 'site-id' );"},{"note":"Request is a static property of the default export.","wrong":"const { Request } = require('wpcom')","symbol":"Request","correct":"import WPCOM from 'wpcom';\nconst req = WPCOM.Request;"}],"quickstart":{"code":"import WPCOM from 'wpcom';\n\n// Initialize with a token (replace with real token in production)\nconst wp = new WPCOM( process.env.WPCOM_TOKEN ?? '' );\n\n// Get site info\nasync function getSiteInfo() {\n  try {\n    const site = await wp.site( 'en.blog.wordpress.com' ).get();\n    console.log( site.name );\n  } catch ( error ) {\n    console.error( error );\n  }\n}\n\ngetSiteInfo();\n\n// Create a post\nasync function createPost() {\n  try {\n    const post = await wp.site( 'my-site.wordpress.com' ).post().add( {\n      title: 'Hello World',\n      content: 'This is my first post via API.'\n    } );\n    console.log( post.ID );\n  } catch ( error ) {\n    console.error( error );\n  }\n}\n\ncreatePost();","lang":"typescript","description":"Initializes a WPCOM client, fetches site info, and creates a new post using async/await."},"warnings":[{"fix":"Use .then() or async/await instead of callback functions.","message":"The library version 5.x dropped support for callbacks; all methods now return Promises.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use import WPCOM from 'wpcom' or const WPCOM = require('wpcom').default.","message":"Version 7.x switched to ESM default export. CommonJS users must use require('wpcom').default.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Use new WPCOM({ token: '...' }) or upgrade to OAuth2 client.","message":"Constructor accepting a token directly is deprecated in favor of OAuth2 token flow.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Generate an API token from your WordPress.com developer settings.","message":"The library requires a valid WordPress.com OAuth2 token; anonymous access is not supported.","severity":"gotcha","affected_versions":"all"},{"fix":"Always call .get() or .add() etc. to execute the request.","message":"Methods like .site() return a Site instance, but do not fetch data until .get() is called.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'7.1.1':16 'activ':51 'alongsid':52 'api':3,14,63,91,98 'authent':74 'automatt':84 'browser':96 'built':34 'client':21,60 'comment':30 'commonj':49 'compat':86 'comprehens':20 'data':33 'definit':41 'differenti':77 'direct':79 'endpoint':92 'ensur':85 'es':46 'esm':45 'includ':27 'integr':64 'interact':23 'javascript':4,8,37,93 'key':76 'librari':5,9,99 'mainten':82 'media':29 'method':66 'modern':36 'modul':47 'oauth2':73 'offer':65 'offici':7 'platform':55 'post':28 'promis':69 'provid':18 'recommend':59 'releas':50 'rest':2,13,90,97 'return':68 'ship':39 'site':26 'support':43,71,80 'typescript':40,100 'user':32 'version':15 'wordpress':94 'wordpress.com':1,12,25,54,62,88,95","created_at":"2026-06-07T17:03:28.633330+00:00","updated_at":"2026-06-07T17:03:28.633330+00:00","problems":[{"fix":"Use import WPCOM from 'wpcom' or const WPCOM = require('wpcom').default;","cause":"Using CommonJS require without .default in version 7+","error":"TypeError: WPCOM is not a constructor"},{"fix":"Use .then() or async/await instead of passing a callback.","cause":"Using a callback function with a method that returns a Promise in version 5+","error":"Error: Callback expected. Use promise instead."},{"fix":"Generate a new token from your WordPress.com developer settings and ensure it's passed correctly.","cause":"Invalid or expired OAuth2 token","error":"401 Unauthorized"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/Automattic/wp-calypso","github":"https://github.com/Automattic/wp-calypso","docs":null,"changelog":null,"pypi":null,"npm":"wpcom","openapi_spec":null,"status_page":null,"smithery":null,"categories":["cms"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}