I found that in some cases the WordPress API was returning HTML not JSON. Inspection of the HTML showed that I was being redirected to the login page by Formidable Registration Plugin when basic authentication failed.
Steps to Resolution
The steps to resolution were,
- Disable all plugins
- Install Basic Auth plugin from https://github.com/WP-API/Basic-Auth
- You MUST do this because although WordPress 5.0 includes the WP API it DOES NOT INCLUDE BASIC AUTH.
- Confusing! Note that it is called “JSON Basic Authentication” in the plugins list not “Basic Authentication”.
- Follow the TutsPlus learning journey (don’t test Filters or oAuth because that functionality has changed).
- GET resources
- POST (create resources)
it is expected that this will succeed. If it does not then you may have issues with URL rewriting in your .htaccess file. Use this fix.
- Activate your plug-ins one-by-one.
- After each activation, test an API call using curl or Postman until you find a plugin that is breaking your system.