Skip to main content

Amazon Web Services

A Short Experiment with the Amazon Connect User API

At the end of July, Amazon introduced the User Management API to Amazon Connect. The User API opens the door for customers and partners to start scripting user setup and maintenance actions, create custom user management applications and modify user data from Lambda functions. For this post, I took a few hours to code up a simple web application that shows a list of users and details for each user. It isn’t too pretty and doesn’t do a whole lot, but if it gives you a sense of what’s possible and how easy is it use to the API, I’ll feel satisfied.

Let’s start with the end product. This app has two screens, a list of Connect users and a Connect user detail view. Every Connect user in the list is clickable and takes you to the details page.

These screens are shown below.

 

 

 

 

 

 

 

 

Nothing too fancy, right? However, if you wanted to make the user details editable or add a button to create a new user, the structure is there for you.

Let’s get into the fun part, some code!

 

Some Code…

I used the Express web app framework with Node. I kept all the code in one file, the index.js and used the Pug templating language to render each of the views. To make the code more readable, I used async methods along with the await keyword. This avoids massively indented callback chains and makes the logic easier to follow by just scanning down the file. More details on the tech stack are in the Helpful Resources section at the end of this post.

I’ve included the code of the two views for reference, but the important part of this post is to look at the User API code, which is in the index.js.

 


const express = require("express");
const app = express();
const AWS = require("aws-sdk");
require("express-async-errors");
const connectInstanceId = "7f03…";
var connectClient = new AWS.Connect({
apiVersion: "2017-08-08",
region: "us-east-1"
});
// serve static content from public directory
app.use(express.static("public"));
// configuration for pug views
app.set("views", "./views");
app.set("view engine", "pug");
// index – list of users
app.get("/", async (req, res) => {
var listUsersParams = {
InstanceId: connectInstanceId
};
var listUsersPromise = connectClient.listUsers(listUsersParams).promise();
var listUsersResponse = await listUsersPromise;
res.render("index", {
title: "Connect Users",
dataList: listUsersResponse.UserSummaryList
});
});
// user detail by user id
app.get("/user/:userId", async (req, res) => {
var userId = req.params.userId;
var describeUserParams = {
InstanceId: connectInstanceId,
UserId: userId
};
var describeUserPromise = connectClient
.describeUser(describeUserParams)
.promise();
var describeUserResult = await describeUserPromise;
res.render("user", {
title: describeUserResult.User.Username,
user: describeUserResult.User
});
});
app.listen(3000, () => console.log("App listening on port 3000!"));

view raw

index.js

hosted with ❤ by GitHub

The first step in using the Connect User API is to load the AWS SDK and create a Connect client object, as shown in lines 8-11. We tell the client object which version of the Connect API to use and what region your Connect instance is in.

From there, we can call individual API methods in the routing methods. For the index view method app.get(“/”)… we call the listUsers method which takes in your Connect instance id and returns a list of user basic info objects. We pass the objects to the view to render and away we go.

For the detail view method app.get(“/user/:userId”)… we call the describeUser method which takes that Connect instance id again, along with the user id of the user you want details on. That method returns a detailed user object. Again, we pass that object to the view to render.

In case you were wondering, because I don’t specify an alternative, this Node app will simply use the default profile credentials from the Amazon Command Line Interface tool installed on the machine. See the Helpful Resources section for a link with details on how to specify alternative credentials.

And that’s really it. No particular secret incantations needed here. Amazon has done a nice job in providing an easy to use, thoroughly documented API. I’d love to see more added to the API, for example to pull out the Queues associated with a Routing Profile, but this is a solid base to start off with. Again, the view code is reproduced below for your curiosity.

 


html
head
title= title
link(rel="stylesheet" href="css/base.css")
body
h2= "Users in my Connect Instance (" + dataList.length + ")"
ul
each val in dataList
li
a(href="user/" + val.Id) #{val.Username}

view raw

index.pug

hosted with ❤ by GitHub


html
head
title= title
link(rel="stylesheet" href="../css/base.css")
body
h2= "Details for " + user.Username
ul
li= "ARN: " + user.Arn
li= "First Name: " + user.IdentityInfo.FirstName
li= "Last Name: " + user.IdentityInfo.LastName
li= "Routing Profile Id: " + user.RoutingProfileId
br
a(href="../") #{"Back"}

view raw

user.pug

hosted with ❤ by GitHub

 

Helpful Resources

 

Thanks for reading. Any questions, comments or corrections are greatly appreciated. Stay tuned next week for another post on the Connect API.

To learn more about what we can do with Amazon Connect, check out Helping You Get the Most Out of Amazon Connect

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Peter Miller

Peter Miller is a Solutions Architect at Perficient focused on call center solutions including Amazon Connect

More from this Author

Follow Us