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

I formerly had the JSON API and JSON USER API plugins working before 4.7 and I have seen the documentation at the ReST API User reference, https://developer.wordpress.org/rest-api/reference/users/#create-a-user%20%22ReST%20API%20reference but I don’t know how to get started. I’m sure there is an authentication procedure that must happen first to get a nonce, but I don’t know how to do that anymore either. I’d really appreciate it if someone would show me or point me to some example cURL statements and URI’s for both getting the nonce and creating a user.

TIA

2 s
2

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:

  • https://wordpress.org/plugins/rest-api-oauth1/
  • https://wordpress.org/plugins/application-passwords/
  • https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/

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:

  • https://github.com/WP-API/Basic-Auth

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:

Using the REST API

Authentication

Leave a Comment