Verify a REST API key from Workspace ONE
Last updated December 27th, 2023
Categories:
Environment
- Knox E-FOTA
- Workspace ONE
- Windows PowerShell ISE
Overview
If you created a REST API key in Workspace ONE, you can test your API key and account credentials with PowerShell ISE.
How to verify a REST API key from Workspace ONE
To test your REST API key:
-
Open Windows PowerShell ISE.
-
Create a new script.
-
Paste the following script, and enter values for userName, password, RestAPIKey, and vmwareServer:
$userName = ''
$password = ''
$RestAPIKey = ''
$vmwareServer = "https://"
$pagesize = 10
Function Get - BasicUserForAuth {
Param([string] $func_username)
$userNameWithPassword = $func_username
$encoding = [System.Text.Encoding]::ASCII.GetBytes($userNameWithPassword)
$encodedString = [Convert]::ToBase64String($encoding)
Return "Basic " + $encodedString
}
Function Build - Headers {
Param([string] $authorizationString, [string] $tenantCode, [string] $acceptType, [string] $contentType)
$authString = $authorizationString
$tcode = $tenantCode
$accept = $acceptType
$content = $contentType
$header = @ {
"Authorization" = $authString;
"aw-tenant-code" = $tcode;
"Accept" = $useJSON;
"Content-Type" = $useJSON
}
Return $header
}
# # Login to AW section
$concateUserInfo = $userName + ":" + $password
$restUserName = Get - BasicUserForAuth($concateUserInfo)
$useJSON = "application/json"
$headers = Build - Headers $restUserName $RestAPIKey $useJSON $useJSON
#Get ALL devices that API rest account allowed to get
Clear - variable - Name "URIstring" - Force - EA SilentlyContinue
$URIstring = $vmwareServer + "/api/mdm/devices/search?" + "pagesize=" + $pagesize
$DeviceOutput = Invoke - RestMethod - Method Get - Uri $URIstring - Headers $headers
#display number of retrieved devices
@($DeviceOutput.devices).length
- Press F5 to execute the script.
If your account credentials and REST API key are valid, the script returns the number of devices currently enrolled in Workspace ONE.
On this page
Is this page helpful?