{"id":49758,"library":"wpapi","title":"node-wpapi","description":"An isomorphic JavaScript client for the WordPress REST API, enabling query-builder-style requests from Node.js or browser environments. Current stable version is 1.2.2, with a release cadence of major versions every few years. Key differentiators: built for the official WordPress REST API (WordPress 5.0+), supports auto-discovery, custom routes, media uploads, pagination, and embedding. Unlike generic HTTP clients, wpapi provides fluent methods for posts, comments, categories, tags, and custom post types, with built-in authentication support (Basic Auth, OAuth, nonces).","status":"active","version":"1.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/wp-api/node-wpapi","tags":["javascript","api","client","cms","wordpress"],"install":[{"cmd":"npm install wpapi","lang":"bash","label":"npm"},{"cmd":"yarn add wpapi","lang":"bash","label":"yarn"},{"cmd":"pnpm add wpapi","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export, not named. In TypeScript, use `import WPAPI from 'wpapi'` or `const WPAPI = require('wpapi').default` for CommonJS.","wrong":"const wpapi = require('wpapi')","symbol":"WPAPI","correct":"import WPAPI from 'wpapi'"},{"note":"EndpointRequest is a static property of WPAPI, not a separate export. Use WPAPI.EndpointRequest after default import.","wrong":"const { EndpointRequest } = require('wpapi')","symbol":"EndpointRequest","correct":"import WPAPI from 'wpapi'; const request = WPAPI.EndpointRequest;"},{"note":"registerRoute is an instance method, not a static function. Must be called on a WPAPI instance.","wrong":"import { registerRoute } from 'wpapi'","symbol":"registerRoute","correct":"const site = new WPAPI({ endpoint: 'https://example.com/wp-json' }); site.registerRoute('myplugin/v1', '/resource/(?P<id>\\\\d+)')"}],"quickstart":{"code":"import WPAPI from 'wpapi';\n\nasync function main() {\n  const site = new WPAPI({\n    endpoint: process.env.WP_ENDPOINT || 'https://wordpress.org/wp-json',\n    username: process.env.WP_USERNAME ?? '',\n    password: process.env.WP_PASSWORD ?? ''\n  });\n\n  // Fetch categories\n  const categories = await site.categories().get();\n  console.log('Categories:', categories);\n\n  // Create a new post\n  if (site.username && site.password) {\n    const post = await site.posts().create({\n      title: 'Hello from node-wpapi',\n      content: 'This post was created via the REST API.',\n      status: 'draft'\n    });\n    console.log('Post created:', post.id);\n  }\n\n  // Update a post\n  if (site.username && site.password) {\n    const updated = await site.posts().id(1).update({\n      title: 'Updated title'\n    });\n    console.log('Post updated:', updated.title)\n  }\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Demonstrates basic CRUD operations: fetching categories, creating a post with auth, and updating a post by ID."},"warnings":[{"fix":"Ensure your WordPress site runs version 5.0 or later. For older versions, use the WP REST API plugin and check compatibility.","message":"Usage with WordPress versions older than 5.0 is not officially supported; some endpoints may not exist or behave differently.","severity":"breaking","affected_versions":"<1.0"},{"fix":"Call `.get()` or similar at the end: `site.posts().get()` returns a Promise.","message":"Methods like `posts()`, `comments()` etc. return a handler instance, not a Promise. Chain `.get()`, `.create()`, `.update()`, `.delete()` to execute the request.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use `site.posts().embed().get()` instead of `site.posts().get().embed()`.","message":"The `.embed()` method must be called before the HTTP method (e.g., `.get()`) to include embedded data.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use dedicated setter methods: `site.posts().perPage(10).get()` instead of `site.posts().param('per_page', 10).get()`.","message":"The `.param()` method is deprecated in favor of using setter methods directly (e.g., `.perPage()`, `.page()`, `.categories()`) or passing an object to the handler.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always set auth on the instance: `new WPAPI({ endpoint, username, password })` or call `site.auth({ username, password })`.","message":"If using Basic Auth, the library does not send credentials automatically unless you pass `username` and `password` in constructor options or use `.auth()` method. CORS issues may arise in browsers.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'1.2.2':28 '5.0':49 'api':12,47,89 'auth':85 'authent':82 'auto':52 'auto-discoveri':51 'basic':84 'browser':22 'builder':16 'built':41,80 'built-in':79 'cadenc':32 'categori':72 'client':7,64,90 'cms':91 'comment':71 'current':24 'custom':54,75 'differenti':40 'discoveri':53 'embed':60 'enabl':13 'environ':23 'everi':36 'fluent':67 'generic':62 'http':63 'isomorph':5 'javascript':6,88 'key':39 'major':34 'media':56 'method':68 'node':2 'node-wpapi':1 'node.js':20 'nonc':87 'oauth':86 'offici':44 'pagin':58 'post':70,76 'provid':66 'queri':15 'query-builder-styl':14 'releas':31 'request':18 'rest':11,46 'rout':55 'stabl':25 'style':17 'support':50,83 'tag':73 'type':77 'unlik':61 'upload':57 'version':26,35 'wordpress':10,45,48,92 'wpapi':3,65 'year':38","created_at":"2026-06-07T17:03:27.761208+00:00","updated_at":"2026-06-07T17:03:27.761208+00:00","problems":[{"fix":"Run `npm install --save wpapi` and ensure import/require path is correct: `import WPAPI from 'wpapi'`.","cause":"Missing npm installation or incorrect import path.","error":"Cannot find module 'wpapi'"},{"fix":"Correct usage: `const site = new WPAPI({ endpoint: 'https://example.com/wp-json' }); site.posts().get();`","cause":"Instantiating WPAPI incorrectly; likely not awaiting the constructor or using wrong variable.","error":"TypeError: site.posts is not a function"},{"fix":"Provide `username` and `password` in the constructor or use `.auth()` method. Ensure the user has appropriate capabilities.","cause":"Missing or incorrect authentication credentials when accessing protected endpoints (create/update/delete).","error":"401 Unauthorized"},{"fix":"For single item requests, use `.id(123).get()` to get a post by ID, which returns an object with `id`.","cause":"Trying to access property on a response that is not the expected object; often because `.get()` returns an array for collections.","error":"Cannot read property 'id' of undefined"}],"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/wp-api/node-wpapi","github":"https://github.com/wp-api/node-wpapi","docs":null,"changelog":null,"pypi":null,"npm":"wpapi","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}}