HomeBlogExternal RequestRegister a New WordPress User REST API

Register a New WordPress User REST API

Register a New WordPress User REST API

I want to share an “External Request” to WordPress API implementation where you can Register a New WordPress user within the bot. For other Use Cases, please refer to this REST API Handbook.

Let’s start…

1. The first step is to get a WordPress Plugin, ‘Basic Authentication handler’, which can be downloaded on github https://github.com/WP-API/Basic-Auth

2. Upload and ‘Activate’ the plugin on your WordPress website. Go to https://yourdomain.com/wp-admin/plugins.php

3. Go to Postman: https://www.postman.com/ and register for a FREE Account. Create a WorkSpace and do a POST Request. Put this on the fields as End Point: https://yourdomain.com/wp-json/wp/v2/users as shown on the image below.

4. Go to “Authorizations’ tab and select ‘Basic Auth’ type.

5. Enter your WordPress Username & Password.

Note: You must have an ‘Admin” Access to use the plugin. 

6. Go to Headers tab and Copy the ‘Authorization’ string starting with ‘Basic’. Save it somewhere. You will use it for authorization in your External Request. 

Let’s go to the fun part, go to your bot dashboard. 

7. Create your flow with 5 blocks, Get Username & Password, Set Email Opt-in, Randomize Password, External Request, and Message

8. Open Get Username & Password block

9. Set the Custom User Fields, ‘usernamevar’ and ‘passwordvar’ to hold the user input for Username and Password. 

10. Set Email Opt-in

11. Randomize Password, Open an Action Block, and go to ‘Actions>Tools> Random Number and set up like the image below. I used the CUF ‘passwordvar’. 

Note: This is to set a Temporary Password for the user. 

12. Open your External Request Block

13. Set the End Point https://yourdomain.com/wp-json/wp/v2/users on the ‘Request URL’. 

14. On Headers tab, Set ‘Authorization’ with the string that you saved earlier – put the whole thing starting with ‘Basic’. Set ‘Content Type’, as ‘application/json’.

15. Open the ‘Body’ tab, and Save the Username, Email, and Password on the CUF’s shown on the image. 

16. The ‘Message Block is used for further instructions and to set proper expectations. 

Everything is set now for you to Run the flow that will Get the User’s Username and Email, Ramdomize a Temporary Password and Save a New User on your WordPress website. 

Create a Ref Link and Share it. That’s it. Enjoy…

© Elegant Bots 2019. All Rights Reserved.