REST API get list of device ID's from deployment

Hi,

I’m plying with server REST API and I’m trying to get list of devices for deployment. I first list deployments and then try to get list of ID’s per device. I’m getting this log (golang):

INFO[0001] deployment:{2020-09-04 20:13:17.053 +0000 UTC pending deployment-4ab9b817-7fcf-4517-a8a9-d2e10c1f4c14 release-7.2 763f1fbe-2006-40fe-9c91-fd4cf85433b4 0001-01-01 00:00:00 +0000 UTC 2 0}  module=client
DEBU[0001] sending request: 
GET /api/management/v1/deployments/deployments/763f1fbe-2006-40fe-9c91-fd4cf85433b4/device_list HTTP/1.1
Host: mendertest.mydomain.com
Authorization: Bearer XXXXXXXXX
DEBU[0001] response: 
HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Fri, 04 Sep 2020 20:16:06 GMT
Server: openresty/1.13.6.2
Vary: Accept-Encoding
X-Deployments-Version: unknown
X-Men-Requestid: 584b509b-afb4-4b3a-b882-25a1711373a5

{"Error":"Resource not found"}  module=mender

I double check paths and ID’s and it seems to be correct. First line is printed actual deployment. I’m using mender server v2.1.1. Any ideas what I’m doing wrong? Thanks.

I do not see anything wrong with the API call. Are you sure the deployment id exists?

Maybe you can run and print this one first:

api/management/v1/deployments/deployments

@peter @tranchitella, anything to add?

I do see that there are two different ids in your first print:

deployment-4ab9b817-7fcf-4517-a8a9-d2e10c1f4c14
763f1fbe-2006-40fe-9c91-fd4cf85433b4

You seem to be using the second one? This could actually just be the request ID, and I suspect the first one is the actual deployment ID

deployment-4ab9b817-7fcf-4517-a8a9-d2e10c1f4c14 is deployment name generated by test + uuid. Actually 763f1fbe-2006-40fe-9c91-fd4cf85433b4 is deployment ID which I used also in request.

Better visible here:

INFO[0001] deployment:{
	"created": "2020-09-10T09:41:25.049Z",
	"status": "pending",
	"name": "deployment-235926fa-e7aa-43d8-80b4-962b223f350b",
	"artifact_name": "release-2.6",
	"id": "938cd4a4-58a9-47b7-8acd-0538f9b725fe",
	"finished": "0001-01-01T00:00:00Z",
	"device_count": 3,
	"retries": 0
}  module=client
DEBU[0001] sending request: 
GET /api/management/v1/deployments/deployments/938cd4a4-58a9-47b7-8acd-0538f9b725fe/device_list HTTP/1.1
Host: mendertest.device.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDAzMzU3MjMsImp0aSI6IjRkMzJjNjZlLWZhMzEtNGVhNS05NWNjLWJkZTllOTU4MTA1OCIsImlzcyI6Im1lbmRlci51c2VyYWRtIiwic3ViIjoiYjY2YTVmYjEtMjA4My00NTQ2LTliMWYtNjQ0NDhiNmZiZTQ1Iiwic2NwIjoibWVuZGVyLioiLCJtZW5kZXIudXNlciI6dHJ1ZX0.bqjammG50_zXJXoCnHRuTjquQHNt71cpXkDUC__ag4DtMARHgBsV5VU-R40AYCiGXr64Oo4BJSlj4dK7V8ZVEUxc17Vv01RVNCYfg_Z49wdNPQF1mgEx3-3BaKEmEt29rEJ8s7Vw7IvwYVswr89dwaWwW47bZVfZBrEb3XdpCvuo22Csc1nSq69OfepiP4SOVDhZeA2KezO2o5gEkB72qqhvYb5OyT-omCDVn2O0CvpYIaWcaVchpGOM3L1OL_UaHh0VJ2qZtoFMGqY-gn7HCRoFW24RN07o4_uny0XuuC7V_M6sSP41n3TaakB3iSMmyVcq-cudCQs1iCRcoj-DjoblNER33EVY48ZUC95FHfHlOId9IxNgKbxLR3afOrjCCSQRKGUGqmJP9ivrSYgd8qxlrIlcAY-wfkIt8nukBQUMaNKeAIOIzdBUP2vn0pRzbTvb9bzq0vBE777xfsmJ-YGml6Q6Ge6hTzNCvUN_XTn9OhriY-twx1KyzY7KIYQy
  module=mender
DEBU[0002] response: 
HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 10 Sep 2020 09:42:04 GMT
Server: openresty/1.13.6.2
Vary: Accept-Encoding
X-Deployments-Version: unknown
X-Men-Requestid: 3606ab93-9ea6-48db-b058-2e5d7df30fd8

{"Error":"Resource not found"}  module=mender

Hm, the “Pending” state could explain this. Until devices actually have checked in with the server to transition this deployment to “InProgress” it will not contain any devices.

@peter/@tranchitella, please correct me if I am wrong

@mirzak is right, the status is in “pending” as long as no device checked for updated

@MarekBelisko, can you please try to call the /deployments/{deployment_id}/statistics end-point instead, and see if you get the statistics about the deployment?

@tranchitella yes I got info about statistics and also number of devices e.g. 2 but cannot get list of device. So in my flow I need to wait until state is changed to in progress and then can get list of devices right? Maybe API docu should be updated :). Thanks.

You should be able to get the device IDs even if the deployment is pending, because that information is contained in a field of the Deployment object. The strange thing is that you receive 404 Not Found, which is not expected unless the deployment ID is wrong, that’s why I’ve asked you to consume the other end-point for statistics.

OK let me check and get back to you with results. Thanks.

OK I tried and still failure while statistics can be read out:

GET /api/management/v1/deployments/deployments/bbb29c16-b7c5-419e-8ddd-ad4dc679b2ce/statistics HTTP/1.1
Host: mendertest.device.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDAzNDg4NTksImp0aSI6IjIzNTg4YzFmLWVhZjctNDlkYS05YmRmLTQ4MDRmOWE5ODY3NiIsImlzcyI6Im1lbmRlci51c2VyYWRtIiwic3ViIjoiYjY2YTVmYjEtMjA4My00NTQ2LTliMWYtNjQ0NDhiNmZiZTQ1Iiwic2NwIjoibWVuZGVyLioiLCJtZW5kZXIudXNlciI6dHJ1ZX0.Wg1xmzmkMBIc37wPWRsu37oqNfT1HbMGU2VC4avYk9d0lksMaeebE-OJbLOlxcpfcDrXhKNeYcNWO2vCLNp2IyU8wAFe3suxPU4ZRgESTZdo_ZBADMKGo8M0_cXT9a2kq49wr6oSVn0Ny1VN25oZDQvzaUOh9b_gt2qh77RdF-99DDa0a4CIsb2xbmleOM6tuS5GJfhxVae8CpaxjN2CCdD5owhgH8OSAvsDTmv55xlC0mqI_lngTuNIT3er5Fa6z0zUGxhU_7hNGEHq0nWRRN1CKKtcDYFomZeCAuofJb-bz3d2kTtgSSi75hKMZbaVeVyzjS9gk77cV7qHRePRZKCguGvS3yU4s6-YfwjU_q8j14IeX4rfJOxlg-vqjtriXjrJy9OXTqgfHgXmIInKwWSJlcUhnQMc6caorApxF8BaFWR6CB8JBEVEKEVywo-4deHNFcdhXZR7lHJq748RJijbaWfoiNTX4G6HSaRnJ_B_xGhk7s2IStMGw6XgP-bs
  module=mender
DEBU[0011] response: 
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 10 Sep 2020 13:21:10 GMT
Pragma: no-cache
Server: openresty/1.13.6.2
Strict-Transport-Security: max-age=63072000; includeSubdomains; preload
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Deployments-Version: unknown
X-Frame-Options: DENY
X-Men-Requestid: 66839b51-be97-4426-bfdf-b75e01c5feef
X-Xss-Protection: 1; mode=block

{"aborted":0,"already-installed":0,"decommissioned":0,"downloading":0,"failure":0,"installing":0,"noartifact":0,"pending":3,"rebooting":0,"success":0}  module=mender

GET /api/management/v1/deployments/deployments/bbb29c16-b7c5-419e-8ddd-ad4dc679b2ce/device_list HTTP/1.1
Host: mendertest.device.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDAzNDg4NTksImp0aSI6IjIzNTg4YzFmLWVhZjctNDlkYS05YmRmLTQ4MDRmOWE5ODY3NiIsImlzcyI6Im1lbmRlci51c2VyYWRtIiwic3ViIjoiYjY2YTVmYjEtMjA4My00NTQ2LTliMWYtNjQ0NDhiNmZiZTQ1Iiwic2NwIjoibWVuZGVyLioiLCJtZW5kZXIudXNlciI6dHJ1ZX0.Wg1xmzmkMBIc37wPWRsu37oqNfT1HbMGU2VC4avYk9d0lksMaeebE-OJbLOlxcpfcDrXhKNeYcNWO2vCLNp2IyU8wAFe3suxPU4ZRgESTZdo_ZBADMKGo8M0_cXT9a2kq49wr6oSVn0Ny1VN25oZDQvzaUOh9b_gt2qh77RdF-99DDa0a4CIsb2xbmleOM6tuS5GJfhxVae8CpaxjN2CCdD5owhgH8OSAvsDTmv55xlC0mqI_lngTuNIT3er5Fa6z0zUGxhU_7hNGEHq0nWRRN1CKKtcDYFomZeCAuofJb-bz3d2kTtgSSi75hKMZbaVeVyzjS9gk77cV7qHRePRZKCguGvS3yU4s6-YfwjU_q8j14IeX4rfJOxlg-vqjtriXjrJy9OXTqgfHgXmIInKwWSJlcUhnQMc6caorApxF8BaFWR6CB8JBEVEKEVywo-4deHNFcdhXZR7lHJq748RJijbaWfoiNTX4G6HSaRnJ_B_xGhk7s2IStMGw6XgP-bs
  module=mender
DEBU[0012] response: 
HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 10 Sep 2020 13:21:10 GMT
Server: openresty/1.13.6.2
Vary: Accept-Encoding
X-Deployments-Version: unknown
X-Men-Requestid: f246d16d-e67f-47b0-9e8f-c269b28285cc

{"Error":"Resource not found"}  module=mender

@tranchitella pls see above log. I can get deployment statistics but not list of devices. Maybe my server version is too old and it was fixed in meantime? I’m using 2.1.1 Thanks