How do I create a user using the new JSON api in 4.7?

The REST API included in WordPress doesn’t actually have authentication built into it.

If you do normal authentication in WordPress by logging in, then your browser will receive a set of cookies. If you send those cookies along with your request, then that will authenticate you to perform the actions in question.

If you need to add authentication for an external service, then you need to install a plugin to handle it. A few are available:

If you’re just testing locally, there is also a Basic Authentication plugin which allows you to simply send your username and password with every request in an Authorization header:

In any case, once you’ve either gotten the proper cookie or enabled the authentication method, then creating a new user is simple. Send a POST request to /wp-json/wp/v2/users with the username, email, and password as the payload.

You can find this documented here:

https://developer.wordpress.org/rest-api/using-the-rest-api/

https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/

Leave a Comment