-
Notifications
You must be signed in to change notification settings - Fork 6
/
UpdatePrinterByID.go
62 lines (51 loc) · 1.75 KB
/
UpdatePrinterByID.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"encoding/xml"
"fmt"
"log"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)
func main() {
// Define the path to the JSON configuration file
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
// Initialize the Jamf Pro client with the HTTP client configuration
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
if err != nil {
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
}
// Printer details to create
updatedPrinter := &jamfpro.ResourcePrinter{
Name: "HP 9th Floor",
Category: "",
URI: "lpd://10.1.20.204/",
CUPSName: "HP_9th_Floor",
Location: "string",
Model: "HP LaserJet 500 color MFP M575",
Info: "string",
Notes: "string",
MakeDefault: true,
UseGeneric: true,
PPD: "9th_Floor_HP.ppd",
PPDPath: "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Resources/Generic.ppd",
PPDContents: "string",
}
id := 1 // Replace with the actual printer ID
response, err := client.UpdatePrinterByID(id, updatedPrinter)
if err != nil {
fmt.Println("Error updating printer:", err)
return
}
fmt.Printf("Printer updated successfully, ID: %d\n", response.ID)
// Fetch the full details of the updated printer
updatedPrinterDetails, err := client.GetPrinterByID(response.ID)
if err != nil {
fmt.Println("Error fetching updated printer details:", err)
return
}
// Marshal the updated printer details to XML for display
printerXML, err := xml.MarshalIndent(updatedPrinterDetails, "", " ")
if err != nil {
log.Fatalf("Error marshaling updated printer to XML: %v", err)
}
fmt.Printf("Updated Printer Details:\n%s\n", printerXML)
}