diff --git a/examples/volume_purchase_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go b/examples/volume_purchase_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go deleted file mode 100644 index e75183e17..000000000 --- a/examples/volume_purchase_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import ( - "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) - } - - // Create the payload - newVPL := jamfpro.ResourceVolumePurchasingLocation{ - // TODO I've messed something up here - } - - // Call the CreateVolumePurchasingLocation function - response, err := client.CreateVolumePurchasingLocation(&newVPL) - if err != nil { - log.Fatalf("Error creating volume purchasing location: %v", err) - } - - // Print the response - fmt.Printf("Created Volume Purchasing Location: %+v\n", response) -} diff --git a/examples/volume_purchasing_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go b/examples/volume_purchasing_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go new file mode 100644 index 000000000..bd1ae573d --- /dev/null +++ b/examples/volume_purchasing_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/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) + } + + // Create the payload + newVPL := &jamfpro.VolumePurchasingLocationCreateUpdateRequest{ + Name: "Test VPP Location", + AutomaticallyPopulatePurchasedContent: true, + SendNotificationWhenNoLongerAssigned: false, + AutoRegisterManagedUsers: true, + SiteID: "-1", // Replace with your actual site ID + ServiceToken: "eyJleHBEYXRlIjoiMjA...", // Replace with your actual service token + } + + // Print the payload for debugging + fmt.Printf("Sending payload: %+v\n", newVPL) + + // Call the CreateVolumePurchasingLocation function + response, err := client.CreateVolumePurchasingLocation(newVPL) + if err != nil { + log.Fatalf("Error creating volume purchasing location: %v", err) + } + + // Print the response + fmt.Printf("Created Volume Purchasing Location: %+v\n", response) +} diff --git a/examples/volume_purchasing_locations/DeleteVolumePurchasingLocationByID/DeleteVolumePurchasingLocationByID.go b/examples/volume_purchasing_locations/DeleteVolumePurchasingLocationByID/DeleteVolumePurchasingLocationByID.go new file mode 100644 index 000000000..dd3ac96eb --- /dev/null +++ b/examples/volume_purchasing_locations/DeleteVolumePurchasingLocationByID/DeleteVolumePurchasingLocationByID.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/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) + } + + // ID of the volume purchasing location you want to delete + locationID := "13" // Replace with the actual ID you want to delete + + // Call the DeleteVolumePurchasingLocationByID function + err = client.DeleteVolumePurchasingLocationByID(locationID) + if err != nil { + log.Fatalf("Error deleting volume purchasing location: %v", err) + } + + fmt.Printf("Successfully deleted volume purchasing location with ID: %s\n", locationID) +} diff --git a/examples/volume_purchase_locations/GetVolumePurchaseLocations/GetVolumePurchaseLocations.go b/examples/volume_purchasing_locations/GetVolumePurchaseLocations/GetVolumePurchaseLocations.go similarity index 92% rename from examples/volume_purchase_locations/GetVolumePurchaseLocations/GetVolumePurchaseLocations.go rename to examples/volume_purchasing_locations/GetVolumePurchaseLocations/GetVolumePurchaseLocations.go index 14266d992..817c3b8bc 100644 --- a/examples/volume_purchase_locations/GetVolumePurchaseLocations/GetVolumePurchaseLocations.go +++ b/examples/volume_purchasing_locations/GetVolumePurchaseLocations/GetVolumePurchaseLocations.go @@ -11,7 +11,7 @@ import ( func main() { // Define the path to the JSON configuration file - configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json" // Initialize the Jamf Pro client with the HTTP client configuration client, err := jamfpro.BuildClientWithConfigFile(configFilePath) diff --git a/examples/volume_purchase_locations/GetVolumePurchasingLocationByID/GetVolumePurchasingLocationByID.go b/examples/volume_purchasing_locations/GetVolumePurchasingLocationByID/GetVolumePurchasingLocationByID.go similarity index 87% rename from examples/volume_purchase_locations/GetVolumePurchasingLocationByID/GetVolumePurchasingLocationByID.go rename to examples/volume_purchasing_locations/GetVolumePurchasingLocationByID/GetVolumePurchasingLocationByID.go index ad343d0bd..148ac5a55 100644 --- a/examples/volume_purchase_locations/GetVolumePurchasingLocationByID/GetVolumePurchasingLocationByID.go +++ b/examples/volume_purchasing_locations/GetVolumePurchasingLocationByID/GetVolumePurchasingLocationByID.go @@ -10,7 +10,7 @@ import ( func main() { // Define the path to the JSON configuration file - configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json" + configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json" // Initialize the Jamf Pro client with the HTTP client configuration client, err := jamfpro.BuildClientWithConfigFile(configFilePath) @@ -19,7 +19,7 @@ func main() { } // Example ID to fetch a specific volume purchasing location - specificID := "1" // Replace with a valid ID + specificID := "13" // Replace with a valid ID // Example of calling GetVolumePurchasingLocationByID fmt.Printf("Fetching volume purchasing location with ID %s...\n", specificID) diff --git a/examples/volume_purchasing_locations/UpdateVolumePurchasingLocationByID/UpdateVolumePurchasingLocationByID.go b/examples/volume_purchasing_locations/UpdateVolumePurchasingLocationByID/UpdateVolumePurchasingLocationByID.go new file mode 100644 index 000000000..62d8df945 --- /dev/null +++ b/examples/volume_purchasing_locations/UpdateVolumePurchasingLocationByID/UpdateVolumePurchasingLocationByID.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "log" + + "github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" +) + +func main() { + // Define the path to the JSON configuration file + configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/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) + } + + id := "14" // Replace with the actual ID of the volume purchasing location you want to update + + // Create the payload + updatedVPL := &jamfpro.VolumePurchasingLocationCreateUpdateRequest{ + Name: "Updated Test VPP Location", + AutomaticallyPopulatePurchasedContent: true, + SendNotificationWhenNoLongerAssigned: false, + AutoRegisterManagedUsers: true, + SiteID: "-1", // Replace with your actual site ID + ServiceToken: "eyJleHBEYXRlIjoiMjAyNi0wNS0w....", // Replace with your actual service token + } + + // Print the payload for debugging + fmt.Printf("Sending payload: %+v\n", updatedVPL) + + // Call the CreateVolumePurchasingLocation function + response, err := client.UpdateVolumePurchasingLocationByID(id, updatedVPL) + if err != nil { + log.Fatalf("Error updating volume purchasing location: %v", err) + } + + // Print the response + fmt.Printf("Updated Volume Purchasing Location: %+v\n", response) +} diff --git a/sdk/jamfpro/jamfproapi_volume_purchasing_locations.go b/sdk/jamfpro/jamfproapi_volume_purchasing_locations.go index a22a8874b..780f009f4 100644 --- a/sdk/jamfpro/jamfproapi_volume_purchasing_locations.go +++ b/sdk/jamfpro/jamfproapi_volume_purchasing_locations.go @@ -75,6 +75,16 @@ type VolumePurchasingSubsetContent struct { AdamId string `json:"adamId"` } +// VolumePurchasingLocationCreateUpdateRequest represents the request structure for creating or updating a volume purchasing location. +type VolumePurchasingLocationCreateUpdateRequest struct { + Name string `json:"name,omitempty"` + AutomaticallyPopulatePurchasedContent bool `json:"automaticallyPopulatePurchasedContent"` + SendNotificationWhenNoLongerAssigned bool `json:"sendNotificationWhenNoLongerAssigned"` + AutoRegisterManagedUsers bool `json:"autoRegisterManagedUsers"` + SiteID string `json:"siteId,omitempty"` + ServiceToken string `json:"serviceToken"` +} + // CRUD // VPP Locations @@ -117,11 +127,11 @@ func (c *Client) GetVolumePurchasingLocationByID(id string) (*ResourceVolumePurc } // CreateVolumePurchasingLocation creates a new volume purchasing location. -func (c *Client) CreateVolumePurchasingLocation(request *ResourceVolumePurchasingLocation) (*ResponseVolumePurchasingLocationCreate, error) { +func (c *Client) CreateVolumePurchasingLocation(request *VolumePurchasingLocationCreateUpdateRequest) (*ResponseVolumePurchasingLocationCreate, error) { endpoint := uriVolumePurchasingLocations - var response ResponseVolumePurchasingLocationCreate - resp, err := c.HTTP.DoRequest("POST", endpoint, request, &response) + var responseLocation ResponseVolumePurchasingLocationCreate + resp, err := c.HTTP.DoRequest("POST", endpoint, request, &responseLocation) if err != nil { return nil, fmt.Errorf("failed to create volume purchasing location: %v", err) } @@ -130,16 +140,17 @@ func (c *Client) CreateVolumePurchasingLocation(request *ResourceVolumePurchasin defer resp.Body.Close() } - return &response, nil + return &responseLocation, nil } // UpdateVolumePurchasingLocationByID updates a specific volume purchasing location by its ID. -func (c *Client) UpdateVolumePurchasingLocationByID(id string) (*ResourceVolumePurchasingLocation, error) { +func (c *Client) UpdateVolumePurchasingLocationByID(id string, request *VolumePurchasingLocationCreateUpdateRequest) (*ResourceVolumePurchasingLocation, error) { endpoint := fmt.Sprintf("%s/%s", uriVolumePurchasingLocations, id) + var responseLocation ResourceVolumePurchasingLocation - resp, err := c.HTTP.DoRequest("PATCH", endpoint, nil, &responseLocation) + resp, err := c.HTTP.DoRequest("PATCH", endpoint, request, &responseLocation) if err != nil { - return nil, fmt.Errorf(errMsgFailedGetByID, "vpp locations", id, err) + return nil, fmt.Errorf("failed to update volume purchasing location: %v", err) } if resp != nil && resp.Body != nil { @@ -151,7 +162,7 @@ func (c *Client) UpdateVolumePurchasingLocationByID(id string) (*ResourceVolumeP // DeleteVolumePurchasingLocationByID deletes a specific volume purchasing location by its ID. func (c *Client) DeleteVolumePurchasingLocationByID(id string) error { - endpoint := uriVolumePurchasingLocations + endpoint := fmt.Sprintf("%s/%s", uriVolumePurchasingLocations, id) resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil) if err != nil { return fmt.Errorf(errMsgFailedDeleteByID, "vpp location", id, err)