With upKeeper API it is possible to do everything that you are doing in upKeeper web, this article it will describe how to do some GET operation, for example list all computers in a organization.
To access upKeeper API it will need a upKeeper User whit a upKeeper roll.
To create a upKeeper roll, go to upKeeper Administration -> Roll-> Create a new Roll and give a suitable name. Next step is to give the roll permissions. I have give Computer_list and Computer_view
To Create a upKeeper user, go to upKeeper Administration -> User -> Create a new User and give a suitable name (If upKeeper is running 4.3 or higher, make sure that it is marked as a "User is a service account" else you have to use two factor authentication). Add the roll that was created for this assignment and select organization. Save.
In this example it will use upKeeper solutions demo environment, remember to change address for upKeeper API that match your organization and upKeeper user
Start powershell as administrator.
################################################################
# 1. Set up the connection to the API
################################################################
#Configure URL to upKeeper API
$baseUrl = "https://upKeeperApiUrl"
$apiUrl = "$baseUrl/api"
$tokenUrl = "$baseUrl/token"
# Get Credentials
$myCreds = Get-Credential -Message "Enter API Username"
# Create body for login (MFA is not activated in upKeeper Admin api)
$loginBody = @{
UserName = $myCreds.UserName
Password = $myCreds.GetNetworkCredential().Password
grant_type = "password"
client_id = "ngAuthApp"
}
# Create body for login (MFA is activated in upKeeper Admin api)
$loginBody = @{
UserName = $myCreds.UserName
Password = $myCreds.GetNetworkCredential().Password
grant_type = "password"
client_id = "ngAuthApp"
pin=$null
}
# Acquire an API access token
$token = Invoke-RestMethod -Uri $tokenUrl -Method Post -Body $loginBody -ContentType "application/json"
# Header for subsequent REST API calls
$header = @{Authorization="$($token.token_type) "+$token.access_token}
# Save the user_organizations in the variable $allOrg
$allOrg = $token.user_organizations | ConvertFrom-Json
# Set standard-parameters for Invoke-RestMethod
$PSDefaultParameterValues = @{
"Invoke-RestMethod:Headers" = $header
"Invoke-RestMethod:ContentType" = "application/json;charset=utf-8"
"Invoke-RestMethod:Verbose" = $true
}
# Use Out-GridView to select the organization to work with
$selectedOrg = $allOrg | Out-GridView -PassThru
$orgNumber = $selectedOrg.Number
$orgId = $selectedOrg.Id
################################################################
# 2. List computers, devices and applications
################################################################
# Get all computers in organization
# GET api/{organizationNumber}/ComputerNames
$allComputers = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/ComputerNames"
# Get all devices in organization
# GET api/{organizationNumber}/DeviceNames
$allDevices = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/DeviceNames"
# Get all applications in organization
# GET api/{organizationNumber}/Applications
$allApplications = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/Applications"
################################################################
# 3. Get information of a specific computer
################################################################
# Select a specific computer in my organization to work with
$selectedComputer = $allComputers | Out-GridView -PassThru
$computerID = $selectedComputer.Key
# Get ComputerDetail of selected computer
# GET api/{organizationNumber}/ComputerDetail/{id}
$computerDetails = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/ComputerDetail/$computerID"
# More information in ClientInfromation
$computerDetails.ClientInformation
# Get HardwareInventory of selected computer
# GET api/{organizationNumber}/Computers/{computerId}/HardwareInventory
$computerHWInventory = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/Computers/$computerID/HardwareInventory"
# Get SoftwareInventory of selected computer
# GET api/{organizationNumber}/Computers/{computerId}/SoftwareInventory
$computerSWInventory = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/Computers/$computerID/SoftwareInventory"
Comments
1 comment
You can add more information in to the header and get cleaner calls for methods. Thanks Markus Ullin for this input.
################################################################
# 1. Set up the connection to the API
################################################################
#Configure URL to upKeeper API
$baseUrl = "https://upKeeperApiUrl"
$apiUrl = "$baseUrl/api"
$tokenUrl = "$baseUrl/token"
# Get Credentials
$myCreds = Get-Credential -Message "Enter API Username"
# Create body for login
$loginBody = @{
UserName = $myCreds.UserName
Password = $myCreds.GetNetworkCredential().Password
grant_type = "password"
client_id = "ngAuthApp"
}
# Acquire an API access token
$token = Invoke-RestMethod -Uri $tokenUrl -Method Post -Body $loginBody -ContentType "application/json"
# Header for subsequent REST API calls
$header = @{Authorization="$($token.token_type) "+$token.access_token}
# Save the user_organizations in the variable $allOrg
$allOrg = $token.user_organizations | ConvertFrom-Json
# Set standard-parameters for Invoke-RestMethod
$PSDefaultParameterValues = @{
"Invoke-RestMethod:Headers" = $header
"Invoke-RestMethod:ContentType" = "application/json;charset=utf-8"
"Invoke-RestMethod:Verbose" = $true
}
# Use Out-GridView to select the organization to work with
$selectedOrg = $allOrg | Out-GridView -PassThru
$orgNumber = $selectedOrg.Number
$orgId = $selectedOrg.Id
################################################################
# 2. List computers, devices and applications
################################################################
# Get all computers in organization
# GET api/{organizationNumber}/ComputerNames
$allComputers = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/ComputerNames"
# Get all devices in organization
# GET api/{organizationNumber}/Users
$allDevices = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/DeviceNames"
# Get all applications in organization
# GET api/{organizationNumber}/Applications
$allUsers = Invoke-RestMethod -Method Get -Uri "$apiURL/$orgNumber/Applications"
Please sign in to leave a comment.