The WordPress REST API lets applications read and manage site content through predictable HTTP endpoints. This guide provides a reusable checklist for discovering endpoints, querying posts, requesting media, handling pagination, authenticating write operations, and diagnosing common failures without depending on a particular JavaScript framework or WordPress installation.
Overview
A WordPress REST API request usually combines a site URL, an endpoint, query parameters, and an HTTP method. For a site at https://example.com, the main API index is:
GET https://example.com/wp-json/
The index describes available namespaces and routes. WordPress core endpoints commonly use the wp/v2 namespace. For example, posts are available at:
GET https://example.com/wp-json/wp/v2/posts
Use GET to retrieve data, POST to create a resource, PUT or POST where the endpoint supports updates, and DELETE to remove a resource. Confirm the endpoint's supported methods and required fields before sending a write request. Custom post types, plugins, and themes can add routes outside the core namespace, so do not assume every site exposes the same schema.
For public content, begin without credentials. This makes it easier to separate routing, filtering, and response problems from authentication problems. Add authentication only when the request needs protected content or a write operation.
Useful endpoint patterns
/wp-json/— API index and namespace discovery./wp-json/wp/v2/posts— collection of posts./wp-json/wp/v2/posts/{id}— one post by numeric ID./wp-json/wp/v2/pages— pages./wp-json/wp/v2/media— media library items./wp-json/wp/v2/categoriesand/wp-json/wp/v2/tags— taxonomy terms.
These are starting points rather than a complete route list. Inspect the API index and the target site's behavior before building a long-lived integration.
Checklist by scenario
Scenario 1: Retrieve a list of posts
- Confirm the site's API base URL and whether the REST API is reachable.
- Choose the post status and content type your application should display.
- Use filters for search, date ranges, categories, authors, or specific IDs.
- Request only the fields your client needs.
- Read the pagination headers and continue until the required page is available.
A focused request might look like this:
GET https://example.com/wp-json/wp/v2/posts?search=accessibility&per_page=10&page=1&_fields=id,date,link,title,excerpt
The _fields parameter can reduce response size by selecting properties such as id, date, link, title, and excerpt. Treat the returned shape as an API contract for your application: if the client needs rendered HTML, request the relevant rendered field rather than assuming every title or content value is plain text.
Scenario 2: Filter and sort content
Common collection parameters include:
| Parameter | Purpose | Example |
|---|---|---|
page | Select a result page | page=2 |
per_page | Set results per page within the site's accepted limit | per_page=10 |
search | Search available text fields | search=api |
include | Request specific resource IDs | include=12,18,27 |
exclude | Leave specific resource IDs out | exclude=4 |
orderby | Choose a supported sort field | orderby=date |
order | Choose ascending or descending order | order=desc |
after and before | Limit results by date or time | after=2025-01-01T00:00:00 |
_fields | Limit returned properties | _fields=id,title,link |
Taxonomy filters commonly use IDs rather than names. Resolve a category or tag first, then pass its ID to the post query. Check the route documentation or an actual response for custom post type parameters because plugins and custom registrations may expose different filters.
Scenario 3: Handle pagination reliably
Collection responses include pagination information in response headers. The X-WP-Total header indicates the total number of matching items, while X-WP-TotalPages indicates the number of result pages. A client should inspect both headers rather than infer completion from the number of items in the current response.
For a simple client, request page one, read the total-page count, and continue until the requested page is reached. For a complete synchronisation, continue until the current page is greater than the total-page count. Keep the requested page size reasonable, and handle a response indicating that a page is unavailable instead of retrying indefinitely.
Scenario 4: Retrieve media
Media requests use the /wp/v2/media route. You can filter media by search terms, dates, author, MIME type, or parent where the installation supports those parameters. A post response may contain a featured media ID; use that ID to request the corresponding media object and select its source URL, alternative text, caption, or available sizes.
GET https://example.com/wp-json/wp/v2/media/42?_fields=id,source_url,alt_text,caption,media_details
Do not assume that every media item has useful alternative text or that every image has the same size metadata. Let the consuming application handle missing values and validate URLs before displaying them.
Scenario 5: Create or update content
Write operations require authentication and a request body that matches the endpoint schema. With cURL and an application password, a post creation request can follow this pattern:
curl --user "API_USER:APPLICATION_PASSWORD" \
--header "Content-Type: application/json" \
--data '{"title":"API draft","content":"Draft content","status":"draft"}' \
https://example.com/wp-json/wp/v2/posts
Use a draft status while testing. Store credentials outside source control, use HTTPS, and give the integration only the account access it needs. For updates, target a specific resource such as /posts/42 and send only fields that should change.
Scenario 6: Call the API from JavaScript
A public read request can use the browser's fetch API:
const url = new URL('https://example.com/wp-json/wp/v2/posts');
url.searchParams.set('per_page', '10');
url.searchParams.set('_fields', 'id,title,link');
const response = await fetch(url);
if (!response.ok) {
throw new Error(`WordPress request failed: ${response.status}`);
}
const posts = await response.json();
console.log(posts);
For authenticated browser requests, avoid placing reusable credentials in frontend code. A server-side integration, a carefully configured same-site flow, or an approved authentication solution is generally more appropriate for protected operations.
Authentication choices
Choose authentication according to where the request runs and what it must do:
- Cookie authentication: Useful for requests made inside an authenticated WordPress session, typically with the appropriate REST nonce. It fits same-site administrative experiences but is not a general-purpose credential for an external service.
- Application passwords: A practical option for supported WordPress installations and server-to-server integrations. Treat the generated credential like a password, use HTTPS, and revoke or replace it when the integration no longer needs access.
- OAuth: Appropriate when an external integration needs a delegated authorization flow. Availability and implementation depend on the site's configuration or an authentication provider.
- Plugin-based authentication: Some plugins add token or key-based methods. Review the plugin's supported routes, token storage model, permissions, and maintenance status before making it a dependency.
Authentication is separate from authorization. A valid credential may still lack permission to create, edit, publish, or delete a resource. Test the smallest operation first and confirm the account role and endpoint permissions.
What to double-check
- Base URL: Use the site's canonical HTTPS address and confirm that
/wp-json/is not being blocked by a proxy, security layer, or server rule. - Content type: Confirm the route for custom post types and whether it is publicly queryable or exposed through REST.
- Field shape: Check whether values are objects containing rendered text, IDs, or raw values. Do not hard-code assumptions from one response without testing empty and populated fields.
- Pagination: Read
X-WP-TotalandX-WP-TotalPages, handle unavailable pages, and prevent unbounded loops. - Encoding: URL-encode search terms and other query values. Use JSON encoding for request bodies rather than assembling JSON by string concatenation.
- HTML safety: Treat content returned by an API as data. Apply the sanitisation and rendering rules appropriate to your application before inserting HTML into a page.
- Errors: Log the HTTP status, WordPress error code, message, and request context without logging passwords, tokens, or complete sensitive payloads.
When an API contract is central to a larger application, record representative responses and validate them during development. API debugging tools, an HTTP client, or a simple cURL request can reveal whether a failure is caused by the route, parameters, credentials, or client-side parsing.
Common mistakes
- Using an admin URL instead of the REST route: The dashboard path and API path serve different purposes. Start with
/wp-json/and inspect available namespaces. - Sending credentials for public reads: Unauthenticated reads are simpler and reduce exposure. Add credentials only when needed.
- Assuming page size is unlimited: The site may impose a maximum or modify accepted values. Build pagination around the response, not a fixed assumption.
- Ignoring status codes: A response can be valid JSON while still representing an error. Check
response.okor the numeric status before parsing it as a successful result. - Publishing during a test: Use draft content and a test account where possible. Confirm the final request body and status before enabling automated publishing.
- Exposing application passwords in frontend bundles: Anything shipped to a browser can be inspected. Keep long-lived credentials on a controlled server.
- Expecting plugin routes to behave like core routes: Custom routes may use different namespaces, fields, permissions, and error formats. Read their documentation and test them independently.
When to revisit
Return to this checklist before a seasonal publishing cycle, after changing themes or plugins, when moving a site to a new host, or whenever an integration changes from reading content to writing it. Recheck the API index, authentication method, custom post type routes, pagination behavior, and response fields after significant WordPress or plugin updates.
Before release, run this short operational checklist:
- Test public reads and protected writes separately.
- Verify credentials are stored outside the repository and are not printed in logs.
- Test empty results, invalid IDs, unavailable pages, and permission failures.
- Confirm that retries cannot duplicate a post or media upload.
- Review how rendered content, links, images, and missing fields are displayed.
- Record the endpoint namespace, expected fields, and authentication assumptions for the next maintainer.
For related API workflow checks, see the OpenAPI linting and validation guide and the webhook testing and replay guide. A small, documented request checklist is often enough to make WordPress integrations easier to test, safer to update, and less dependent on guesswork.