|
| 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 | +} |
0 commit comments