How to remotely create a user on your WordPress Website using JSON API Request

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.20 out of 5)
Loading...
April 10, 2015

Do you run a membership website using WordPress as your platform? Or do you maintain your users for your web application on WordPress because of its ease of use and other features provided out of the box? In that case, you might have come across times when you needed to add users to your wordpress remotely and without much hassle. WordPress is a very powerful tool and comes with a bunch of APIs that you can use to achieve this functionality, i.e. create a user remotely. However, there is one easy way for you to do it, without having to write complicated codes. You can use JSON API to create users on WordPress.

The first step to do is to install WordPress JSON API plugin. The next step is to install another plugin known as JSON API User. Once you install both of these plugins, you will see “JSON API” under WordPress settings. JSON API User offers a bunch of options to fetch posts, add comments etc. and the JSON API User plugin that depends on the JSON API Plugin adds an icing on the cake by allowing you to remotely create users as well. So, on the settings page for this plugin, activate teh “User” creation option  and save your settings. Below it you will see an API base URL which by default is api. Change api to something that is hard to guess, something like sdf23234sdf and save the settings. Now you are ready to roll.

The first step is to get the nonce ID which is required to create a new user remotely. To obtain this ID, open the the URL in the following format:

http://domain.com/api/get_nonce/?controller=user&method=register

Here replace domain with your domain name and api with the api base you created in the earlier step. This will give you the nonce id in the following format:

{“status”:”ok”,”controller”:”user”,”method”:”register”,”nonce”:”92d7431951″}

Now copy the nonce ID which in the above case is 92d7431951(Note that this ID needs to be generated every time you need to create a new user, its not static).

Now use this ID in the following URL format to create a new user:

http://domain.com/APIBASE/user/register/?username=john&email=john@domain.com&nonce=NONCEID&display_name=John

Make sure to replace domain, APIBASE and NONCEID with the appropriate ones.

Now when you open the above URL, you will see a message saying that the user has been created.

Thats it. This will create a new user with the role that has been set up as default in your wordpress environment. By default, its “Subscriber” but you can change it to other roles from the Settings>General page using theNew User Default role dropdown field.

Thats it, now you can use simply send a request via s URL and a new user will be instantly created in your wordpress installation.

You may also like...