Admin API - Java

Hi There,

I need some assistance in calling DUO api for admin activities like create user, edit user, delete user. I am almost done but I need assistance on below one

Pre-request Script for HTTP requests
The Duo APIs use HTTP Basic Authentication. The password value expected with each request is a hash of several concatenated request elements. Due to the dynamic nature of the HTTP Basic Authentication value needed for each request to the API, additional configuration is needed within Postman. Postman provides the ability to execute Javascript code prior to the HTTP request being sent. This is accomplished using the Pre-request Script setting within each HTTP request.

Before sending a request it calls the javascript for HTTP Basic Authentication.

Can I get the same JavaScript code in Java?

Have you taken a look at our Java API example client? It shows how to construct the HTTP request with signing.

Hi Kristina,

Thanks for your response.

when i am using the code as Option opt; opt = new Option("api-XXXXXXXX.com", true, "API hostname (required)");

i am getting error as

Exception in thread "main" java.lang.IllegalArgumentException: opt contains illegal character value '-'

Please help me out here.

It looks like you’re trying to specify the value of the option with that class, rather than setting up a command-line option itself.

Here’s how it’s done in the example API client.

Hi Kristina,

Thanks for your help , i manage to complete below task
1- Create User
2- Create Phone
3- Associate Phone and user.

Now i am struggling to send OR code over the email of user. Please help me

Hi Kristina,

As an alternate option I am generating an activation code /admin/v1/phones/[phone_id]/activation_url and then i am calling /admin/v1/phones/[phone_id]/send_sms_activation.
Below is my code

Http request = new Http.HttpBuilder("POST", cmd.getOptionValue("host"),
					"/admin/v1/phones/" + phone_id + "/send_sms_activation").build();
request.addParam("installation_msg", "Welcome To MQF Sandhya Sinha <insturl>");
request.addParam("activation_msg", "Welcome To Marquis Finance Sandhya Sinha To Activate <acturl>");
request.addParam("valid_secs", "60");
request.addParam("install", "1");

By using the above code sometimes it sends only installation_msg that is Welcome To MQF Sandhya Sinha http://m-nnnnnn.duosecurity.com but this one does not have the activation code which is an issue and some time it sends only activation_msg and some time both.

So I am a bit confused what is the correct way , for me activation_msg is the best way because it contains activation code.

Please help

Now i am struggling to send OR code over the email of user

There isn’t an AdminAPI endpoint that will email the activation code. As you noted, send_sms_activation will text the code to the phone’s number.

By using the above code sometimes it sends only installation_msg that is Welcome To MQF Sandhya Sinha http://m-nnnnnn.duosecurity.com but this one does not have the activation code which is an issue and some time it sends only activation_msg and some time both.

Are you trying that POST again within the valid_secs lifetime? The activation code changes on each post but the installation information does not. If you POST and then don’t make the same request again for more than 60 seconds does it resend the installation message too?