EUCbackup Default chapterAdvanced API Automation (copied)

Advanced API Automation (copied)

Overview

This lab will provide hands on training to leverage APIs to perform Automation task in your Workspace ONE UEM Environment. We will use POSTMAN to demonstrate the API automation.

In the industry today, DevOps, Operations and Support teams are leveraging API capability to automate application releases, minimize human interaction and achieve faster troubleshooting. In this lab we will learn how to use these APIs by making a collection of API calls for our DevOps use case.

Use Case: Developer team releases weekly updates to business critical application. Built an automation for this application release to our production devices.

Part 1: Getting Started

This section has 2 parts

  • Setting UP Postman•
  • Accessing the Workspace ONE UEM ApI

Part 1 Setting Up Postman

  • Log in to your Controlcenter server with your administrative credentials
    1. Open your chrome browser in the google search type Postman download. Select the option to Download Postman App
    2. In the Get Postman for Windows select Download
    3. Select the Windows 64bit version to download
    4. Open your Downloads folder on select and Open the Postman-win64. xx installer
    5. Select Run
    6. After the installer has finished you will be prompted to Sign UP
      1. In the Email section type an email (possibly a dummy email you used in previous labs)
      2. Fill in Username
      3. Password VMware1!
      4. Select Create free account
    7. On the Welcome to Postman page select Save My Preferences

Part 2: Accessing the Workspace ONE UEM API

 

All the REST API calls are listed in the API portal. You can access the portal by navigating to https://<WorkspaceONE UEM URL>/api/help. 

  1. On your ControlCenter server, open your browser and navigate to https://cn-livefire.awmdm.com/api/help
  2. You will notice you are the default Overview page. Click on the APIs. tab.
  3. Select and open the MAM (Mobile Application Management) REST API V1  module.
    • One can use the search capability to search for desired API calls' using the Search APIs/ Method field and then typing the name of the API. 
  4. In the MAM (Mobile Application Management) REST API V1 you will land on the Overview page, select the API Reference tab

Part 3: DevOps Automation

  • To meet our use case, DevOps needs the capability of uploading the application to the UEM console, create and assign smart group and publish to specific devices. We will use a total of 4 API calls to achieve the same.

Step 1: Upload Application

Uploading the application in the console comprises of two POST API commands.

  1. uploadblob: Uploads the apk as a blob to the database server.
  2. begininstall: Creates an internal application using the uploaded file blob.

1. Search uploadblob in the Search APIs/ Method field. 

2. Next to POST, Click on blobs/uploadblob

3. Scroll down to the Parameters field and Enter the required fields next to

  • filename : Hello.apk
  • organizationGroupId: your oganizationGroupID

Note: In your Workspace ONE UEM Console, browse to Groups & Settings > Groups > Organization Groups > Details. Look in the address bar of your browser and the last digits will be a /number combination . Copy the ID from the Browser URL. For example: https://cn-livefire.awmdm.com/AirWatch/#/AirWatch/OrganizationGroup/Details/Index/722. In this case, 722 is the organizationGroupId, copy this number to organizationGroupID field

4. Scroll right down to the bottom of the page and Click Try it out!. 

5. Scroll down to see the response of your API call. Copy and Paste the Request URL in the response to Notepad++. 

 

Note: We will use Postman tool to make our API calls and create Automation. 

6. Navigate to the ControlCenter2 Server. Find the Postman icon on your desktop screen. Open Postman application. 

7. Click Request. 

8. In the SAVE REQUEST Window in the Request Name section type DevOps Upload Blob.

 This is the first API call you are creating.

9. Scroll down to +Create Collection. and click on +Create Collection

10. In the Name your Collection area name it Livefire collection. 

11. Select the orange tick box to the right of your entry

12 Click Save to Livefire Collection. 

12. Next to GET, Paste the copied Request URL in the Enter Request URL field in Postman.

 

13.  Change the Request type from GET to POST.

Note the Params value is now populated.

 

14. Below POST next to Params select the  Authorization tab,

15. Below the TYPE area select the drop down and change inherit auth from parent to Basic Auth.

16.  Provide your Workspace ONE UEM admin credentials in the Username and Password field.

 

17. Switch back to the Workspace ONE UEM console

  • Go Groups & Settings > ALL Settings > System > Advanced > API > REST API
  • In the REST API section next the AirWatchAPI - ADMIN section select and copy the API KEY
  • Note Save the API key to Notepad++

18. Switch back to PostMan . On the next tab next to Authorization select Headers,

  • Add the following under the KEY and VALUE areas
 KEY
VALUE
Aw-tenant-code YOUR API ADMIN KEY
Content-Type application/json

19. Next to the Headers tab, switch to the Body tab

  • In the Body section select the Binary radio button
  • In the Binary section click on Select File.
  • Browse to the Downloads folder and select the Hello.apk file. Select Open.

20. From the Body section switch two tabs across and select the Tests tab

  • Under Tests, copy and paste the below json script.
    • This will create a global variable Value and assign the response result of the blob update to this global variable.
  • Click SEND.
    • You should see a 200 OK next to Status.
    • In the body of the response, you will see uuid and value of the uploaded blob
var data = JSON.parse(responseBody);
console.log(JSON.stringify(data));
if (data.hasOwnProperty("Value"))
{
  console.log(data.Value);
  postman.setGlobalVariable("value", data.Value);
}

21. Before we move forward, we will check to confirm the global parameter from our previous call is created.

  1. In PostMan navigate to Settings (Top Right cog wheel)
  2. Select Globals
  3. Check in the list if there exist an entry called 'value' and its CURRENT VALUE matches the output in the response body. We will use this value in the next call.
  4. Click X to Close the MANAGE ENVIRONMENTS window

Part 4: Creating the next API Call

Once Uploadblob is successfully executed, we will pass this blob "value" parameter in the next API call to save as an internal app on the console.

    1. In PostMan Create a new tab by selecting the +New on the top left hand corner
    2. In the Create New window select GET Request
    3. In the SAVE REQUEST window under Request name type Compile APK.
    4. Select Save to Livefire Collection.

 

2. On your ControlCenter server, revert back to your browser In the address bar            https://cn-livefire.awmdm.com/api/help

  1. Under the APIs tab to the right in the Search APIs/Methods area type begininstall.
  2. Click on /apps/internal/begininstall API.
  3. Scroll down to Parameters. In the right part of Parameters next to Parameter Type you will see Data Type, Hover your mouse over the yellow Data Type box and Click. You will see the appChunkTransaction field populated on the left.
  4. Scroll down and Click Try it out!
  5. Scroll down. Copy the Request URL field in the response.

3.

  • Navigate back to Postman,
    1. Under the Compile APK tab next to GET in the Enter Request URL area, paste the copied Request URL.
    2. Change the command type from GET to POST.
    3. Under the newly selected POST. To the right of the Params tab select the Authorization tab
    4. In the Authorization section under TYPE  change Inherit auth from parent to Basic Auth  
    5. To the right fill in your Workspace ONE UEM username and password.
      (this might autofill as its round number 2)

4.

  • Next to the Authorization tab select the Headers tab
  • Under the Headers tab under KEY and VALUE fill in the following values using the table below.
 KEY
VALUE
Aw-tenant-code YOUR API ADMIN KEY
Content-Type application/json

5.

  • Next to Header select the Body Tab ,
    1. select the RAW radio button
      • Ensure that  JSON is select instead of TEXT. (JSON should be default)
    2. Copy and Paste the below sample script.
      • In this example, we have simplified to only include device type Android (Device type- 5),
        Push mode and Organization group.
    3. Replace the LocationGroupId in the sample script with your LocationGroupId documented in Notepad++
      • You could edit the ApplicationName. Leave PushMode in the body of the API call to "Auto".
{
  "BlobId": "{{value}}",
  "DeviceType": "5",
  "ApplicationName": "testapk",
  "SupportedModels": {
    "Model": [
      {
        "ModelId": 0,
        "ModelName": "Android"
      }
    ]
  },
  "PushMode": "Auto",
  "LocationGroupId": 722,
  "CarryOverAssignments": true
}

6.

  • Two tabs down from Body select the Tests tab
    •  In the Tests Tab, we will create a new global variable for our application id.
      • This Application id will be passed in the future to assign the smart group to this application.
var data = JSON.parse(responseBody);
    console.log(data.Id.Value);
    postman.setGlobalVariable("app",data.Id.Value);
  • Click SEND. Confirm the response is 200 OK.

Part 5 : Create a Smart Group

1.

  • Navigate back to your Workspace ONE UEM API console, https://cn-livefire.awmdm.com/api/help
    1. Switch to the APIs tab, in the Search APIs/Methods type Smart Group.
    2. Click on POST /smartgroups.
    3. Scroll down to find the expanded view of the API, under Parameters, to the right under Data Type click over the yellow box
      • This will populate the SmartGroupEditModel field.
    4. Scroll down and click Try It Out! button.  
    5. Scroll until you find the Request URL field, Copy your Request URL  https://as1276.awmdm.com/API/mdm/smartgroups.

2

  • Switch back to Postman.
    1. In the top left-hand corner select +New
    2. Next to GET select Request
    3. In the SAVE REQUEST window, Under Request name type Create Smart Group. Select Save to Livefire Collection
    4. Change the Request type from GET to POST.
    5. In the Enter request URL area Copy and Paste your copied request URL

3.

  • Next to Params select the Authorization tab
    1. Under TYPE change Inherit auth from parent to Basic Auth
    2. Next to Username and Password ensure that your Workspace ONE UEM credentials have auto-filled

4.

  • Switch to the next TAB Headers,
    • Enter the KEY and VALUE configuration in the below table.
 KEY
VALUE
Aw-tenant-code YOUR API ADMIN KEY
Content-Type application/json

5.

  • Next to Headers, switch to the Body Tab
    1. Select the raw radio button
    2. Copy and Paste the below script,
    3. Next to the "ManagedByOrganisationGroupId" and  "Id"  replace the "722" sample code with YOUR "ID"

NOTE: A Customer would use the SmartGroupEditModel and replace values with their own required parameters. For simplicity, below is an example where we create a smart group, 'Livefire smart group' managed at OG with LGID 722.  

 

{
  "Name": "Livefire smart group",
  "CriteriaType": "All",
  "ManagedByOrganizationGroupId": "722",
  "OrganizationGroups": [
    {
      "Id": "722",
    }
  ],
}

 

6 .

  • Select the Tests tab
    • copy the below JSON script. In this script, we are passing the response from create smart group API call to our next call.
var data = JSON.parse(responseBody);
console.log(JSON.stringify(data));
if (data.hasOwnProperty("Value"))
{
    console.log(data.Value);
    postman.setGlobalVariable("SmartGroup", data.Value);
} 
  • Click SEND. Confirm the response Status is 201 Created is displayed.

 

Make sure the Variable "SmartGroup" is created in the Settings of Postman.

 

Part 6: Assign and Publish.

1.

  • Navigate back to your Workspace ONE UEM API console, cn-livefire.awmdm.com/api/help.
    1. Select the APIs tab,
    2. In the Search APIs/Methods area type assignments.
    3. Click on PUT /apps/internal/{applicationId}/assignments
    4. Scroll down to Parameters, to the right, next to Parament Type,
      • Under the Data Type header you will see a yellow box. Click on the Yellow box. This populates the applicationAssignments field to the right
      • Under Parameter next to applicationId enter any number value eg. 444
    5. Scroll down, Click Try it Out!
    6. Scroll down, to the Request URL area. Copy and save the Request URL.
  • Note, the application id will be replaced by Global Variable "app" that was created in the second API call by Tests JSON script.

2.

  • Revert back to Postman.
    1. Create a new Tab by selecting +NEW
    2. On the Create New page next to GET select Request
    3. On the SAVE REQUEST page under Request name type Assign Smart Group. Select Save to Livefire Collection
    4. Change the Request type to PUT or POST.
    5. Copy the Request URL. https://as1276.awmdm.com/api/mam/apps/internal/{{app}}/assignments.
    6. Under POST select the Authorization tab
    7. On the Authorization tab under TYPE change inherit auth from parent to Basic Auth
    8. Verify that your Username and Password fields have automatically been filled in with your Workspace ONE UEM credentials

3.

  • From the Authorization tab, switch to the  Headers tab
    • In Headers populate the respective, KEY and VALUE areas
 KEY
VALUE
Aw-tenant-code YOUR API ADMIN KEY
Content-Type application/json

4.

  • Next switch from the Headers tab and select the Body tab
    • Select the raw radio button. You can copy and paste the body from the API portal. For simplicity, paste the below body.
    • Click Send. Check for 201 Created  response.
{
  "SmartGroupIds": [
    {{SmartGroup}}  ],
  "DeploymentParameters": {
    "PushMode": "Auto",
    "ApplicationBackup": true,
    "IsPerAppVpnEnabled": false,
    "AllowManagement": true,
    "MacOsDesiredStateManagement": true,
    "RequiresApproval": true,
    "VisibleInAppCatalog": true,
  },
}

Note: We are passing the 'SmartGroup' Global variable from the previous API call.

Part 7: Validation

  • Navigate to the Workspace ONE UEM console.
    1. Under Apps&Books > Native. Under the Internal tab Check your APK is added successfully
    2. We will now validate the assignment of the APK. Select the radio button next to your APK icon and click ASSIGN.
    3. On the testapk - Update Assignment window, below  +ADD ASSIGNMENT, notice the Livefire smart group has already been assigned.
    4. Select the radio button next Livefire smart group click EDIT.
    5. Next to Select Assignment Groups is Livefire smart group and next to App Delivery Method the configuration is set to AUTO.
    6. Next to Select Assignment Groups click on Livefire smart group In the criteria confirm your OG is selected under Organization Group.
    7. Cancel all the windows. This confirms all the APIs successfully Executed.

Part 8: Automation

This Section will add all the above 4 API calls in one collection and execute them together to demonstrate automation. Before you begin, delete the APK and Smart Group you just created in the previous section from the workspace ONE UEM console.

 1.

  • In the Workspace ONE UEM console,
    1. Navigate to Apps & Books > Native. Select the APK you uploaded and click DELETE. On the Restricted Action - Application Delete window enter your Security PIN
    2. Click on Filters on the same screen. Expand Status, select All. You will observe the app was not deleted but deactivated from the console. Select the radio button next to the APK click DELETE.
      • Note: This is a safety net in console to ensure Admin do not delete critical production application that have an active assignment.
    3. Navigate to Groups & Settings > Groups > Assignment Groups. Select the check box next to your smart group and click DELETE.

2.  Creating a New Collection.

  • Navigate to POSTMAN.
    1. On the left pane, click + New Collection.
    2. In the CREATE A NEW COLLECTION window under Name type Livefire DevOps.
    3. Click Create.

3 Save all 4 API calls to the new collection.

  • In POSTMAN, from the left panel, click on DevOPs upload blob API call.
    1. Navigate to the right hand side of the window and look for Save which is to the right of Send. Select the drop down arrow next to Save. Click on Save As
    2. In the SAVE REQUEST window and scroll down to All Collections and select Livefire DevOps. and select Save to Livefire DevOps
  • Repeat this task for the remaining 3 API calls, that being
    1. Compile APK
    2. Create Smart Group
    3. Assign Smart Group
  • After you have completed the remaning 3 API calls in the left pane of PostMan expand the Livefire DevOps Collection and check that you have added all 4 requests

4. Run the Collection

Once the API collection is ready and console clean up is completed, you are ready to execute this automation.

  1. Select your collection in POSTMAN.
  2. Click on the play icon.
  3. In the expanded window view, click RUN.
  4. This will open a new window Collection Runner, at the bottom of the window Click Run Livefire DevOps.
  5. Go to your Workspace ONE UEM console and validate the APK is present and smart group is assigned.

You can export the entire collection in a json file and use tools like Newman to execute the same from Command Line. You can perform the same task sequence in Powershell leveraging the Workspace ONE UEM API Portal. This lab uses Postman to simplify and demonstrate API automation for beginners.

To export in JSON, click on the menu Icon (View More Options) next to collection. Click Export to generate a JSON script for your collection. This lab does not demonstrate Newman or Powershell.

0 Comments

Add your comment

E-Mail me when someone replies to this comment