@@ -20,6 +20,16 @@ import (
2020
2121const uriComputersInventory = "/api/v1/computers-inventory"
2222
23+ // computerInventorySections contains all available sections for computer inventory API requests
24+ var computerInventorySections = []string {
25+ "GENERAL" , "DISK_ENCRYPTION" , "PURCHASING" , "APPLICATIONS" , "STORAGE" ,
26+ "USER_AND_LOCATION" , "CONFIGURATION_PROFILES" , "PRINTERS" , "SERVICES" ,
27+ "HARDWARE" , "LOCAL_USER_ACCOUNTS" , "CERTIFICATES" , "ATTACHMENTS" ,
28+ "PLUGINS" , "PACKAGE_RECEIPTS" , "FONTS" , "SECURITY" , "OPERATING_SYSTEM" ,
29+ "LICENSED_SOFTWARE" , "IBEACONS" , "SOFTWARE_UPDATES" , "EXTENSION_ATTRIBUTES" ,
30+ "CONTENT_CACHING" , "GROUP_MEMBERSHIPS" ,
31+ }
32+
2333// List
2434
2535// ResponseComputerInventoryList represents the top-level JSON response structure.
@@ -107,7 +117,7 @@ type ComputerInventorySubsetGeneralRemoteManagement struct {
107117type ComputerInventorySubsetGeneralMdmCapable struct {
108118 Capable bool `json:"capable"`
109119 CapableUsers []string `json:"capableUsers"`
110- UserManagementInfo [][] struct {
120+ UserManagementInfo []struct {
111121 CapableUser string `json:"capableUser"`
112122 ManagementId string `json:"managementId"`
113123 } `json:"userManagementInfo"`
@@ -598,9 +608,17 @@ func (c *Client) GetComputersInventory(params url.Values) (*ResponseComputerInve
598608func (c * Client ) GetComputerInventoryByID (id string ) (* ResourceComputerInventory , error ) {
599609 endpoint := fmt .Sprintf ("%s/%s" , uriComputersInventory , id )
600610
611+ // Add all section parameters to get complete inventory data
612+ params := url.Values {}
613+ for _ , section := range computerInventorySections {
614+ params .Add ("section" , section )
615+ }
616+
617+ endpointWithParams := fmt .Sprintf ("%s?%s" , endpoint , params .Encode ())
618+
601619 // Fetch the computer inventory by ID
602620 var responseInventory ResourceComputerInventory
603- resp , err := c .HTTP .DoRequest ("GET" , endpoint , nil , & responseInventory )
621+ resp , err := c .HTTP .DoRequest ("GET" , endpointWithParams , nil , & responseInventory )
604622 if err != nil {
605623 return nil , fmt .Errorf (errMsgFailedGetByID , "computer inventory" , id , err )
606624 }
@@ -614,7 +632,13 @@ func (c *Client) GetComputerInventoryByID(id string) (*ResourceComputerInventory
614632
615633// GetComputerInventoryByName retrieves a specific computer's inventory information by its name.
616634func (c * Client ) GetComputerInventoryByName (name string ) (* ResourceComputerInventory , error ) {
617- inventories , err := c .GetComputersInventory (nil )
635+ // Add all section parameters to get complete inventory data
636+ params := url.Values {}
637+ for _ , section := range computerInventorySections {
638+ params .Add ("section" , section )
639+ }
640+
641+ inventories , err := c .GetComputersInventory (params )
618642 if err != nil {
619643 return nil , fmt .Errorf (errMsgFailedPaginatedGet , "computer inventory" , err )
620644 }
@@ -628,6 +652,27 @@ func (c *Client) GetComputerInventoryByName(name string) (*ResourceComputerInven
628652 return nil , fmt .Errorf (errMsgFailedGetByName , "computer inventory" , name , err )
629653}
630654
655+ // GetComputerInventoryBySerialNumber retrieves a specific computer's inventory information by its serial number.
656+ func (c * Client ) GetComputerInventoryBySerialNumber (serialNumber string ) (* ResourceComputerInventory , error ) {
657+ // Add filter and all section parameters to get complete inventory data
658+ params := url.Values {}
659+ params .Set ("filter" , fmt .Sprintf ("hardware.serialNumber==\" %s\" " , serialNumber ))
660+ for _ , section := range computerInventorySections {
661+ params .Add ("section" , section )
662+ }
663+
664+ inventories , err := c .GetComputersInventory (params )
665+ if err != nil {
666+ return nil , fmt .Errorf (errMsgFailedPaginatedGet , "computer inventory" , err )
667+ }
668+
669+ if len (inventories .Results ) == 0 {
670+ return nil , fmt .Errorf ("failed to find computer inventory by serial number '%s'" , serialNumber )
671+ }
672+
673+ return & inventories .Results [0 ], nil
674+ }
675+
631676// UpdateComputerInventoryByID updates a specific computer's inventory information by its ID.
632677func (c * Client ) UpdateComputerInventoryByID (id string , inventoryUpdate * ResourceComputerInventory ) (* ResourceComputerInventory , error ) {
633678 endpoint := fmt .Sprintf ("%s/%s" , uriComputersInventory , id )
0 commit comments