Skip to content

Commit 5cc9aa3

Browse files
authored
Merge pull request #51 from deploymenttheory/dev
+ sdk coverage for printers
2 parents 11de98a + ca0b01f commit 5cc9aa3

File tree

11 files changed

+691
-3
lines changed

11 files changed

+691
-3
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,11 +1020,41 @@ This documentation outlines the API endpoints available for managing Mobile Devi
10201020
- [x] ✅ **DELETE** `/JSSResource/mobiledeviceenrollmentprofiles/invitation/{invitation}`
10211021
`DeleteMobileDeviceEnrollmentProfileByInvitation` deletes a Mobile Device Enrollment Profile by its invitation.
10221022
1023+
### Jamf Pro Classic API - Printers
1024+
1025+
This documentation outlines the API endpoints available for managing printers within Jamf Pro using the Classic API, which supports XML data structures.
1026+
1027+
## Endpoints
1028+
1029+
- [x] ✅ **GET** `/JSSResource/printers`
1030+
`GetPrinters` retrieves a serialized list of all printers.
1031+
1032+
- [x] ✅ **GET** `/JSSResource/printers/id/{id}`
1033+
`GetPrinterByID` fetches details of a single printer by its ID.
1034+
1035+
- [x] ✅ **GET** `/JSSResource/printers/name/{name}`
1036+
`GetPrinterByName` retrieves details of a printer by its name.
1037+
1038+
- [x] ✅ **POST** `/JSSResource/printers/id/0`
1039+
`CreatePrinters` creates a new printer. The ID `0` in the endpoint indicates creation.
1040+
1041+
- [x] ✅ **PUT** `/JSSResource/printers/id/{id}`
1042+
`UpdatePrinterByID` updates an existing printer by its ID.
1043+
1044+
- [x] ✅ **PUT** `/JSSResource/printers/name/{name}`
1045+
`UpdatePrinterByName` updates an existing printer by its name.
1046+
1047+
- [x] ✅ **DELETE** `/JSSResource/printers/id/{id}`
1048+
`DeletePrinterByID` deletes a printer by its ID.
1049+
1050+
- [x] ✅ **DELETE** `/JSSResource/printers/name/{name}`
1051+
`DeletePrinterByName` deletes a printer by its name.
1052+
10231053
10241054
## Progress Summary
10251055
1026-
- Total Endpoints: 331
1027-
- Covered: 312
1056+
- Total Endpoints: 339
1057+
- Covered: 320
10281058
- Not Covered: 19
10291059
- Partially Covered: 0
10301060
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
id := 1 // Replace with the actual printer ID
41+
42+
err = client.DeletePrinterByID(id)
43+
if err != nil {
44+
fmt.Println("Error deleting printer:", err)
45+
return
46+
}
47+
48+
fmt.Println("Printer deleted successfully")
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
name := "HP 9th Floor" // Replace with the actual printer name
41+
42+
err = client.DeletePrinterByName(name)
43+
if err != nil {
44+
fmt.Println("Error deleting printer:", err)
45+
return
46+
}
47+
48+
fmt.Println("Printer deleted successfully")
49+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Instantiate the default logger and set the desired log level
23+
logger := http_client.NewDefaultLogger()
24+
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
25+
26+
// Configuration for the jamfpro
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
LogLevel: logLevel,
30+
Logger: logger,
31+
ClientID: authConfig.ClientID,
32+
ClientSecret: authConfig.ClientSecret,
33+
}
34+
35+
// Create a new jamfpro client instance
36+
client, err := jamfpro.NewClient(config)
37+
if err != nil {
38+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
39+
}
40+
41+
// Example ID to fetch
42+
printerID := 1
43+
44+
printer, err := client.GetPrinterByID(printerID)
45+
if err != nil {
46+
fmt.Println("Error fetching printer by ID:", err)
47+
return
48+
}
49+
50+
// Pretty print the created script details in XML
51+
createdPrintersXML, err := xml.MarshalIndent(printer, "", " ") // Indent with 4 spaces
52+
if err != nil {
53+
log.Fatalf("Error marshaling created script data: %v", err)
54+
}
55+
fmt.Println("Created Script Details:\n", string(createdPrintersXML))
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Instantiate the default logger and set the desired log level
23+
logger := http_client.NewDefaultLogger()
24+
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
25+
26+
// Configuration for the jamfpro
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
LogLevel: logLevel,
30+
Logger: logger,
31+
ClientID: authConfig.ClientID,
32+
ClientSecret: authConfig.ClientSecret,
33+
}
34+
35+
// Create a new jamfpro client instance
36+
client, err := jamfpro.NewClient(config)
37+
if err != nil {
38+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
39+
}
40+
41+
// Example ID to fetch
42+
printerName := "printer-name"
43+
44+
printer, err := client.GetPrinterByName(printerName)
45+
if err != nil {
46+
fmt.Println("Error fetching printer by ID:", err)
47+
return
48+
}
49+
50+
// Pretty print the created script details in XML
51+
createdPrintersXML, err := xml.MarshalIndent(printer, "", " ") // Indent with 4 spaces
52+
if err != nil {
53+
log.Fatalf("Error marshaling created script data: %v", err)
54+
}
55+
fmt.Println("Created Script Details:\n", string(createdPrintersXML))
56+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client" // Import http_client for logging
9+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
10+
)
11+
12+
func main() {
13+
// Define the path to the JSON configuration file
14+
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/clientauth.json"
15+
16+
// Load the client OAuth credentials from the configuration file
17+
authConfig, err := jamfpro.LoadClientAuthConfig(configFilePath)
18+
if err != nil {
19+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
20+
}
21+
22+
// Instantiate the default logger and set the desired log level
23+
logger := http_client.NewDefaultLogger()
24+
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
25+
26+
// Configuration for the jamfpro
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
LogLevel: logLevel,
30+
Logger: logger,
31+
ClientID: authConfig.ClientID,
32+
ClientSecret: authConfig.ClientSecret,
33+
}
34+
35+
// Create a new jamfpro client instance
36+
client, err := jamfpro.NewClient(config)
37+
if err != nil {
38+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
39+
}
40+
41+
printers, err := client.GetPrinters()
42+
if err != nil {
43+
fmt.Println("Error fetching printers:", err)
44+
return
45+
}
46+
47+
// Pretty print the created script details in XML
48+
createdPrintersXML, err := xml.MarshalIndent(printers, "", " ") // Indent with 4 spaces
49+
if err != nil {
50+
log.Fatalf("Error marshaling created script data: %v", err)
51+
}
52+
fmt.Println("Created Script Details:\n", string(createdPrintersXML))
53+
}

0 commit comments

Comments
 (0)