Skip to main content

Hello,



So, I have been trying to obtain a specific data from UAPI, but keep getting 404 errors, which is a response code that it cannot find the data requested... I am able to generate and authenticate with the token fine and I am even able to pull lists, for example pulling the list of all computers via:



computerslistall=$(curl -X GET --header "Authorization: Bearer $token" "Accept: application/json" "$jssurl/uapi/preview/computers")


Is working fine and if I echo $computerslistall - I get a full list of all computers currently in JSS. However, when I am trying to obtain a specific computer, no matter what I try I get 404... I have tried:
$jssurl/uapi/preview/computers/id/XXXX
$jssurl/uapi/preview/computers/ComputerOverview/id/XXXX
$jssurl/uapi/preview/computers/results/id/XXXX



So far I have been unable to find any GET example where a specific data is obtained via UAPI. Would appreciate if anybody has any info/explanation/example on this.



Here is a full script code, if anybody needs a working token creation/user via UAPI - this should work for you:



# server connection information
jssurl="https://jss.XXXXXX.com:8443"
username="XXXXXX"
password="XXXXXXXX"

# created base64-encoded credentials
encodedCredentials=$( printf "$username:$password" | /usr/bin/iconv -t ISO-8859-1 | /usr/bin/base64 -i - )

# generate an auth token
authToken=$( /usr/bin/curl "$jssurl/uapi/auth/tokens"
--silent
--request POST
--header "Authorization: Basic $encodedCredentials" )

# parse authToken for token, omit expiration
token=$( /usr/bin/awk -F " '{ print $4 }' <<< "$authToken" | /usr/bin/xargs )

# get existing json for PreStage ID | TESTING TOKEN / DATA retreival via UAPI
#prestageJson=$( /usr/bin/curl "$jssurl/uapi/v1/computer-prestages/$prestageID/scope" --silent --request GET --header "Authorization: Bearer $token" )
#echo "prestageJson is: $prestageJson"


#Start the UAPI scripts#
computerslistall=$(curl -X GET --header "Authorization: Bearer $token" "Accept: application/json" "$jssurl/uapi/preview/computers")
echo "computerslistall is: $computerslistall"
#End the UAPI scripts#

# expire the auth token
/usr/bin/curl "$jssurl/uapi/auth/invalidateToken"
--silent
--request POST
--header "Authorization: Bearer $token"

exit 0


It is also very hard to find anything on UAPI, as it keeps finding old API stuff lol

Since I continue to explore the UAPI 🙂. do you know by any chance if PATCHing computer name on JSS is not available yet as well?

As I get 404 error when trying to do it:

 

curl --request PATCH \\
--url "https://jss.MYCOMPANY.com:8443/uapi/v1/computers-inventory-detail/$id" \\
--header "Accept: application/json" \\
--header "Authorization: Bearer $token" \\
--header "Content-Type: application/json" \\
--data '
{
"general":
{
"name" : "'$computernameinput'"
}
}
'

 

 


Yes, updating the name is supported. Make sure to check the center column of the documentation to determine what inputs are allowed by the endpoint you're referencing. The right column, which you included a screenshot of provides an example of a successful response (not the request). I've included a screenshot for reference, which shows that "name" is a supported element in the request body:

The following format is a valid request body:

{
"general": {
"name": "NewDeviceName"
}
}

Finally, the error you're getting seems to be unrelated to the request body. 404 means that the server couldn't find the resource that you specified, in this case, the device ID. Make sure the variable you're using is set properly and/or being passed properly. If you're not super familiar with an API operation or the coding language, it's generally a good idea to ensure the code you're writing works first with hardcoded values, then work backwards to make it scalable/reusable, by substituting in the variables.


Yes, updating the name is supported. Make sure to check the center column of the documentation to determine what inputs are allowed by the endpoint you're referencing. The right column, which you included a screenshot of provides an example of a successful response (not the request). I've included a screenshot for reference, which shows that "name" is a supported element in the request body:

The following format is a valid request body:

{
"general": {
"name": "NewDeviceName"
}
}

Finally, the error you're getting seems to be unrelated to the request body. 404 means that the server couldn't find the resource that you specified, in this case, the device ID. Make sure the variable you're using is set properly and/or being passed properly. If you're not super familiar with an API operation or the coding language, it's generally a good idea to ensure the code you're writing works first with hardcoded values, then work backwards to make it scalable/reusable, by substituting in the variables.


You are the best 🙂

404 means that the server couldn't find the resource that you specified, in this case, the device ID - that was the case, I had a miss-type for the JSS URL so it couldn't locate the actual ID, I guess I misinterpreted the 404 error, once I set the correct JSS URL it worked like a charm. Thank You!


What I was working on mainly is LAPS to work via the new UAPI, if anybody has a need for it - you can find it here: https://gist.github.com/shurkin18 

A bunch of thanks to @SamF , I would be otherwise stuck for a while 🙂


@sam11, hey Sam, so far UAPI is working well for me. The only thing is, when I update something on the UAPI using curl --request PATCH - it updates fine, but also prints out all the information about the mac as well, which is making it hard to read the logs...

 

For example, this command:

 

curl --request PATCH \\
--url "$apiURL/uapi/v1/computers-inventory-detail/$id" \\
--header "Accept: application/json" \\
--header "Authorization: Bearer $token" \\
--header "Content-Type: application/json" \\
--data '
{
"general":
{
"extensionAttributes":
[
{
"definitionId" : "'$currentstatusid'",
"values" : ["'$issuedstatus'"]
}
]
}
}
'

 

updates an extension attribute by it's id correctly, but also parses ALL the information about the mac, such as:

 

{
"id" : "2670",
"udid" : "55FC5FA2-21********************",
"general" : {
"name" : "MM-MA*******",
"lastIpAddress" : "172**********6",
"lastReportedIp" : "19***********56",
"jamfBinaryVersion" : "10.30.3-t1624643096",
"platform" : "Mac",
"barcode1" : null,
"barcode2" : null,
"assetTag" : "6*******6",
"remoteManagement" : {
"managed" : true,
"managementUsername" : "ak******"
},
"supervised" : true,
"mdmCapable" : {
"capable" : true,
"capableUsers" : [ "ak*****v" ]
},
"reportDate" : "2021-10-01T13:22:28.216

 

I just included a small portion, it prints basically ALL the data about the mac, like if I would run curl GET without trimming.

 

Any ideas how to prevent it from printing all of that info?


@sam11, hey Sam, so far UAPI is working well for me. The only thing is, when I update something on the UAPI using curl --request PATCH - it updates fine, but also prints out all the information about the mac as well, which is making it hard to read the logs...

 

For example, this command:

 

curl --request PATCH \\
--url "$apiURL/uapi/v1/computers-inventory-detail/$id" \\
--header "Accept: application/json" \\
--header "Authorization: Bearer $token" \\
--header "Content-Type: application/json" \\
--data '
{
"general":
{
"extensionAttributes":
[
{
"definitionId" : "'$currentstatusid'",
"values" : ["'$issuedstatus'"]
}
]
}
}
'

 

updates an extension attribute by it's id correctly, but also parses ALL the information about the mac, such as:

 

{
"id" : "2670",
"udid" : "55FC5FA2-21********************",
"general" : {
"name" : "MM-MA*******",
"lastIpAddress" : "172**********6",
"lastReportedIp" : "19***********56",
"jamfBinaryVersion" : "10.30.3-t1624643096",
"platform" : "Mac",
"barcode1" : null,
"barcode2" : null,
"assetTag" : "6*******6",
"remoteManagement" : {
"managed" : true,
"managementUsername" : "ak******"
},
"supervised" : true,
"mdmCapable" : {
"capable" : true,
"capableUsers" : [ "ak*****v" ]
},
"reportDate" : "2021-10-01T13:22:28.216

 

I just included a small portion, it prints basically ALL the data about the mac, like if I would run curl GET without trimming.

 

Any ideas how to prevent it from printing all of that info?


@akamenev47 is it possible you could throw in a silent argument in with your headers? 

--url "$apiURL/uapi/v1/computers-inventory-detail/$id" \\
--silent \\
--header "Accept: application/json" \\
--header "Authorization: Bearer $token" \\

 

If you aren't looking to get data back, this should run the curl silently in Terminal. 


@akamenev47 is it possible you could throw in a silent argument in with your headers? 

--url "$apiURL/uapi/v1/computers-inventory-detail/$id" \\
--silent \\
--header "Accept: application/json" \\
--header "Authorization: Bearer $token" \\

 

If you aren't looking to get data back, this should run the curl silently in Terminal. 


@JDGates, tried that, unfortunately it still prints all that data...