Skip to content

Commit

Permalink
Merge pull request #190 from deploymenttheory/dev
Browse files Browse the repository at this point in the history
+ new example to library
  • Loading branch information
ShocOne authored Feb 1, 2024
2 parents b2025a9 + c0b2e40 commit da1f366
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
63 changes: 63 additions & 0 deletions examples/dock_items/DeleteAllDockItems/DeleteAllDockItems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
"log"

"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)

func main() {
// Define the path to the JSON configuration file
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"

// Load the client OAuth credentials from the configuration file
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
if err != nil {
log.Fatalf("Failed to load client OAuth configuration: %v", err)
}

// Instantiate the default logger and set the desired log level
logger := http_client.NewDefaultLogger()
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug

// Configuration for the jamfpro
config := jamfpro.Config{
InstanceName: authConfig.InstanceName,
OverrideBaseDomain: authConfig.OverrideBaseDomain,
LogLevel: logLevel,
Logger: logger,
ClientID: authConfig.ClientID,
ClientSecret: authConfig.ClientSecret,
}

client, err := jamfpro.NewClient(config)
if err != nil {
log.Fatalf("Failed to create Jamf Pro client: %v", err)
}

// Fetch all dock items
dockItems, err := client.GetDockItems()
if err != nil {
log.Fatalf("Error fetching dock items: %v", err)
}

fmt.Println("Dock items fetched. Starting deletion process:")

// Iterate over each dock item and delete
for _, dockItem := range dockItems.DockItems {
fmt.Printf("Deleting dock item ID: %d, Name: %s\n", dockItem.ID, dockItem.Name)

err = client.DeleteDockItemByID(dockItem.ID)
if err != nil {
log.Printf("Error deleting dock item ID %d: %v\n", dockItem.ID, err)
continue // Move to the next dock item if there's an error
}

fmt.Printf("Dock item ID %d deleted successfully.\n", dockItem.ID)
}

fmt.Println("Dock item deletion process completed.")

}
2 changes: 1 addition & 1 deletion examples/printers/GetPrinterByID/GetPrinterByID.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
}

// Example ID to fetch
printerID := 1
printerID := 356

printer, err := client.GetPrinterByID(printerID)
if err != nil {
Expand Down

0 comments on commit da1f366

Please sign in to comment.