Documentation-Issue-Tracker icon indicating copy to clipboard operation
Documentation-Issue-Tracker copied to clipboard

Doc Missing: REST API is only accessible until Permalinks configured.

Open tybalex opened this issue 10 months ago • 3 comments

I am working on a project that uses REST API to manage WordPress sites.

I kept getting empty response from REST API calls (for instance: curl --user "username:password" localhost:8070/wp-json/wp/v2/posts). After debugging for several hours I found out that the REST API wp-json endpoint won't be available till permalinks got configured.

I can't find anything related to this step in the REST API documentation. Should we add this to the docs?

tybalex avatar Jan 21 '25 05:01 tybalex

You shouldn't assume that Permalinks are configured on a site, and should use the HTTP Header to discover the endpoint, for example:

$ curl -I https://example.org/

Link: <https://example.org/?rest_route=/>; rel="https://api.w.org/"
...
<link rel="https://api.w.org/" href="https://example.org/?rest_route=/" />

This likely isn't something that needs documenting, but I'll transfer this issue to the Docs issue tracker.

This is probably covered by the Discovery page: https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/

dd32 avatar Jan 21 '25 05:01 dd32

Heads up @WordPress/docs-issues-coordinators, we have a new issue open. Time to use 'em labels.

github-actions[bot] avatar Jan 21 '25 05:01 github-actions[bot]

You shouldn't assume that Permalinks are configured on a site, and should use the HTTP Header to discover the endpoint, for example:

Thank you for the response. That curl command was just an example, I do have HTTP Header attached when calling REST API in my dev/production sites.

And my point is: exactly because user shouldn't assume permalinks are configured on a site, the REST API documentation should alert user that -- if the REST API isn't working for your website, double check if permalinks are configured

tybalex avatar Jan 21 '25 06:01 tybalex