Sitecore Content Hub is a really powerful solution for any organisation. If offers endless extension possibilities and is a solid foundation for your digital assets and content.

I am currently the solution architect on a Content Hub solution for a global brand which has over 2500 users. They use Content Hub across the entire globe and the organisation wanted to understand how many of these users were actually using the system.

The main metric they wanted to calculate the adoption rate of the system by users.

Within Content Hub you can open the users section and see all of the users. However we wanted a quick way to export all users with their last login date. Within the users screen you are limited in the data you can select and would be a manual job to retrieve the data.


Query the API

This is where Postman comes in and with some basic queries return the data that you need.

You will need the following

  • Content Hub instance
  • Postman
  • API user

Start off by installing Postman and generating an API auth token with Content Hub.

Within Postman set up a new GET request for the URL of your Content Hub instance – https://{{CHURL}}/api/Users. Add a header for X-Auth-Token entering your Auth token from Content Hub.

In the ‘Tests’ tab you can enter the following JS code to loop over the results

 var jsonData = pm.response.json();
 let moment = require ('moment');
 jsonData.items.forEach(function(item)
 {
     let id = item.properties.Username;
     let date = item.properties.LastLoginDateTime;
     
     if (item.properties.UserGroupConfiguration != null && item.properties.UserGroupConfiguration.user_group_ids != null)
        {
            let userGroups = item.properties.UserGroupConfiguration.user_group_ids;
            pm.test(id + "," + moment(date).format('DD-MM-YYYY') + ",'" + userGroups+ "\n");
        }
    else
    {
        pm.test(id + "," + moment(date).format('DD-MM-YYYY') + "," + "NO GROUPS"+ "\n");
    }
 })

All you have to do is send the request and within Postman you can will start seeing the results of the query return as Test cases.

The Content Hub API is extremely powerful and when used in a tool like Postman can really help you get the data you need.

Leave a Reply