|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging |
| 8 | + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" |
| 9 | +) |
| 10 | + |
| 11 | +func main() { |
| 12 | + // Define the path to the JSON configuration file |
| 13 | + configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json" |
| 14 | + |
| 15 | + // Load the client OAuth credentials from the configuration file |
| 16 | + authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath) |
| 17 | + if err != nil { |
| 18 | + log.Fatalf("Failed to load client OAuth configuration: %v", err) |
| 19 | + } |
| 20 | + |
| 21 | + // Instantiate the default logger and set the desired log level |
| 22 | + logger := http_client.NewDefaultLogger() |
| 23 | + logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug |
| 24 | + |
| 25 | + // Configuration for the jamfpro |
| 26 | + config := jamfpro.Config{ |
| 27 | + InstanceName: authConfig.InstanceName, |
| 28 | + LogLevel: logLevel, |
| 29 | + Logger: logger, |
| 30 | + ClientID: authConfig.ClientID, |
| 31 | + ClientSecret: authConfig.ClientSecret, |
| 32 | + } |
| 33 | + |
| 34 | + // Create a new jamfpro client instance |
| 35 | + client, err := jamfpro.NewClient(config) |
| 36 | + if err != nil { |
| 37 | + log.Fatalf("Failed to create Jamf Pro client: %v", err) |
| 38 | + } |
| 39 | + |
| 40 | + // Printer details to create |
| 41 | + newPrinter := &jamfpro.ResponsePrinters{ |
| 42 | + Name: "HP 9th Floor", |
| 43 | + Category: "", |
| 44 | + URI: "lpd://10.1.20.204/", |
| 45 | + CUPSName: "HP_9th_Floor", |
| 46 | + Location: "string", |
| 47 | + Model: "HP LaserJet 500 color MFP M575", |
| 48 | + Info: "string", |
| 49 | + Notes: "string", |
| 50 | + MakeDefault: true, |
| 51 | + UseGeneric: true, |
| 52 | + PPD: "9th_Floor_HP.ppd", |
| 53 | + PPDPath: "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Resources/Generic.ppd", |
| 54 | + PPDContents: "string", |
| 55 | + } |
| 56 | + |
| 57 | + createdPrinter, err := client.CreatePrinters(newPrinter) |
| 58 | + if err != nil { |
| 59 | + fmt.Println("Error creating printer:", err) |
| 60 | + return |
| 61 | + } |
| 62 | + |
| 63 | + fmt.Printf("Printer created successfully:\nID: %d\nName: %s\n", createdPrinter.ID, createdPrinter.Name) |
| 64 | +} |
0 commit comments