Skip to content

Instantly share code, notes, and snippets.

@Yohan460
Last active June 13, 2022 19:11
Show Gist options
  • Save Yohan460/3dead3d7ea40ad1a7545c7b6afea32bc to your computer and use it in GitHub Desktop.
Save Yohan460/3dead3d7ea40ad1a7545c7b6afea32bc to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"github.com/yohan460/go-jamf-api/api"
)
func main() {
// Setup the basic client
client := api.NewAPIClient(&api.Configuration{
Servers: []api.ServerConfiguration{
{
URL: "https://server.jamfcloud.com/api",
},
},
})
// Setup the Basic HTTP authentication context for the Token Request
clientBasicCtx := context.WithValue(context.Background(), api.ContextBasicAuth, api.BasicAuth{
UserName: "username",
Password: "password",
})
// Request a Bearer Token
tokenResp, _, err := client.ApiAuthenticationApi.V1AuthTokenPost(clientBasicCtx).Execute()
if err != nil {
panic(err)
}
// Setup the Bearer token based authentication context
clientBearerCtx := context.WithValue(context.Background(), api.ContextAccessToken, *tokenResp.Token)
// Query Jamfs Computer Inventory endpoint using the token authentication context
searchResp, _, err := client.ComputerInventoryApi.V1ComputersInventoryGet(clientBearerCtx).Execute()
if err != nil {
panic(err)
}
// Printout the device list
for _, device := range searchResp.Results {
fmt.Println("Device ID:", *device.Id, "-", *device.General.Name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment