Skip to content

Commit 53610c1

Browse files
committed
+ users to sdk with examples
1 parent 1b7dc70 commit 53610c1

File tree

13 files changed

+956
-60
lines changed

13 files changed

+956
-60
lines changed

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,56 @@ This documentation outlines the operations available for managing Buildings with
20052005
- Total Operations Covered: 8
20062006
- Total Operations Not Covered: 1
20072007

2008+
### Jamf Pro Classic API - Users
2009+
2010+
This documentation outlines the operations available for managing Users within Jamf Pro using the Classic API, which supports XML data structures.
2011+
2012+
## Operations
2013+
2014+
- [x]**GET** `/JSSResource/users`
2015+
- `GetUsers` operation retrieves a serialized list of all Users.
2016+
2017+
- [x]**GET** `/JSSResource/users/id/{id}`
2018+
- `GetUserByID` operation fetches a specific User by their ID.
2019+
2020+
- [x]**GET** `/JSSResource/users/name/{name}`
2021+
- `GetUserByName` operation fetches a specific User by their name.
2022+
2023+
- [x]**GET** `/JSSResource/users/email/{email}`
2024+
- `GetUserByEmail` operation fetches a specific User by their email.
2025+
2026+
- [x]**POST** `/JSSResource/users/id/0`
2027+
- `CreateUser` operation creates a new User.
2028+
2029+
- [x]**PUT** `/JSSResource/users/id/{id}`
2030+
- `UpdateUserByID` operation updates an existing User by their ID.
2031+
2032+
- [x]**PUT** `/JSSResource/users/name/{name}`
2033+
- `UpdateUserByName` operation updates an existing User by their name.
2034+
2035+
- [x]**PUT** `/JSSResource/users/email/{email}`
2036+
- `UpdateUserByEmail` operation updates an existing User by their email.
2037+
2038+
- [x]**DELETE** `/JSSResource/users/id/{id}`
2039+
- `DeleteUserByID` operation deletes a User by their ID.
2040+
2041+
- [x]**DELETE** `/JSSResource/users/name/{name}`
2042+
- `DeleteUserByName` operation deletes a User by their name.
2043+
2044+
- [x]**DELETE** `/JSSResource/users/email/{email}`
2045+
- `DeleteUserByEmail` operation deletes a User by their email.
2046+
2047+
## Summary
2048+
2049+
- Total Endpoints Covered: 3
2050+
- `/JSSResource/users`
2051+
- `/JSSResource/users/id/{id}`
2052+
- `/JSSResource/users/name/{name}`
2053+
- `/JSSResource/users/email/{email}`
2054+
2055+
- Total Operations Covered: 11
2056+
2057+
20082058
### Jamf Pro Classic API - User Groups
20092059

20102060
This documentation outlines the operations available for managing User Groups within Jamf Pro using the Classic API, which supports XML data structures.
@@ -2047,8 +2097,8 @@ This documentation outlines the operations available for managing User Groups wi
20472097

20482098
## Progress Summary
20492099

2050-
- Total Operations: 364
2051-
- Total Covered Operations: 342
2100+
- Total Operations: 375
2101+
- Total Covered Operations: 353
20522102
- Not Covered: 22
20532103
- Partially Covered: 0
20542104
- Deprecated:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
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 // Adjust log level as needed
24+
25+
// Configuration for the jamfpro
26+
config := jamfpro.Config{
27+
InstanceName: authConfig.InstanceName,
28+
OverrideBaseDomain: authConfig.OverrideBaseDomain,
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+
// Create a sample user to be created
42+
newUser := &jamfpro.ResponseUser{
43+
ID: 1,
44+
Name: "AHarrison",
45+
FullName: "Ashley Harrison",
46+
47+
EmailAddress: "[email protected]",
48+
PhoneNumber: "123-555-6789",
49+
Position: "Teacher",
50+
Sites: []jamfpro.UserDataSubsetSite{
51+
{
52+
ID: -1,
53+
Name: "None",
54+
},
55+
},
56+
}
57+
58+
// Call the CreateUser function
59+
createdUser, err := client.CreateUser(newUser)
60+
if err != nil {
61+
log.Fatalf("Error creating user: %v", err)
62+
}
63+
64+
// Print the details of the created user
65+
fmt.Printf("Created User Details:\nID: %d\nName: %s\nEmail: %s\n", createdUser.ID, createdUser.Name, createdUser.Email)
66+
}
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"
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 // Adjust log level as needed
24+
25+
// Configuration for the jamfpro
26+
config := jamfpro.Config{
27+
InstanceName: authConfig.InstanceName,
28+
OverrideBaseDomain: authConfig.OverrideBaseDomain,
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+
userEmail := "[email protected]" // Example user email to delete
42+
43+
err = client.DeleteUserByEmail(userEmail)
44+
if err != nil {
45+
log.Fatalf("Error deleting user by email: %v", err)
46+
}
47+
48+
fmt.Println("User deleted successfully by email")
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"
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 // Adjust log level as needed
24+
25+
// Configuration for the jamfpro
26+
config := jamfpro.Config{
27+
InstanceName: authConfig.InstanceName,
28+
OverrideBaseDomain: authConfig.OverrideBaseDomain,
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+
userID := 1 // Example user ID to delete
42+
43+
err = client.DeleteUserByID(userID)
44+
if err != nil {
45+
log.Fatalf("Error deleting user by ID: %v", err)
46+
}
47+
48+
fmt.Println("User deleted successfully by ID")
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"
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 // Adjust log level as needed
24+
25+
// Configuration for the jamfpro
26+
config := jamfpro.Config{
27+
InstanceName: authConfig.InstanceName,
28+
OverrideBaseDomain: authConfig.OverrideBaseDomain,
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+
userName := "AHarrison" // Example user name to delete
42+
43+
err = client.DeleteUserByName(userName)
44+
if err != nil {
45+
log.Fatalf("Error deleting user by name: %v", err)
46+
}
47+
48+
fmt.Println("User deleted successfully by name")
49+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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"
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 // Adjust log level as needed
25+
26+
// Configuration for the jamfpro
27+
config := jamfpro.Config{
28+
InstanceName: authConfig.InstanceName,
29+
OverrideBaseDomain: authConfig.OverrideBaseDomain,
30+
LogLevel: logLevel,
31+
Logger: logger,
32+
ClientID: authConfig.ClientID,
33+
ClientSecret: authConfig.ClientSecret,
34+
}
35+
36+
// Create a new jamfpro client instance
37+
client, err := jamfpro.NewClient(config)
38+
if err != nil {
39+
log.Fatalf("Failed to create Jamf Pro client: %v", err)
40+
}
41+
42+
// Specify the email of the user you want to retrieve
43+
email := "[email protected]" // Replace with the desired email address
44+
45+
// Call the GetUserByEmail function
46+
user, err := client.GetUserByEmail(email)
47+
if err != nil {
48+
log.Fatalf("Error fetching user by email: %v", err)
49+
}
50+
51+
// Pretty print the user details in XML
52+
userXML, err := xml.MarshalIndent(user, "", " ") // Indent with 4 spaces
53+
if err != nil {
54+
log.Fatalf("Error marshaling user data: %v", err)
55+
}
56+
fmt.Println("User Details:\n", string(userXML))
57+
}

0 commit comments

Comments
 (0)