Skip to content

feat: complete volume purchasing location support #777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
27 changes: 19 additions & 8 deletions sdk/jamfpro/jamfproapi_volume_purchasing_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
Loading