Skip to content

Commit 408ed30

Browse files
authored
feat: add volume purchasing location management examples and update SDK methods (#777)
1 parent 784b2a8 commit 408ed30

File tree

7 files changed

+136
-44
lines changed

7 files changed

+136
-44
lines changed

examples/volume_purchase_locations/CreateVolumePurchasingLocation/CreateVolumePurchasingLocation.go

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
13+
14+
// Initialize the Jamf Pro client with the HTTP client configuration
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// Create the payload
21+
newVPL := &jamfpro.VolumePurchasingLocationCreateUpdateRequest{
22+
Name: "Test VPP Location",
23+
AutomaticallyPopulatePurchasedContent: true,
24+
SendNotificationWhenNoLongerAssigned: false,
25+
AutoRegisterManagedUsers: true,
26+
SiteID: "-1", // Replace with your actual site ID
27+
ServiceToken: "eyJleHBEYXRlIjoiMjA...", // Replace with your actual service token
28+
}
29+
30+
// Print the payload for debugging
31+
fmt.Printf("Sending payload: %+v\n", newVPL)
32+
33+
// Call the CreateVolumePurchasingLocation function
34+
response, err := client.CreateVolumePurchasingLocation(newVPL)
35+
if err != nil {
36+
log.Fatalf("Error creating volume purchasing location: %v", err)
37+
}
38+
39+
// Print the response
40+
fmt.Printf("Created Volume Purchasing Location: %+v\n", response)
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
13+
14+
// Initialize the Jamf Pro client with the HTTP client configuration
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
// ID of the volume purchasing location you want to delete
21+
locationID := "13" // Replace with the actual ID you want to delete
22+
23+
// Call the DeleteVolumePurchasingLocationByID function
24+
err = client.DeleteVolumePurchasingLocationByID(locationID)
25+
if err != nil {
26+
log.Fatalf("Error deleting volume purchasing location: %v", err)
27+
}
28+
29+
fmt.Printf("Successfully deleted volume purchasing location with ID: %s\n", locationID)
30+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func main() {
1313
// Define the path to the JSON configuration file
14-
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
14+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
1515

1616
// Initialize the Jamf Pro client with the HTTP client configuration
1717
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func main() {
1212
// Define the path to the JSON configuration file
13-
configFilePath := "/Users/dafyddwatkins/localtesting/jamfpro/clientconfig.json"
13+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
1414

1515
// Initialize the Jamf Pro client with the HTTP client configuration
1616
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
@@ -19,7 +19,7 @@ func main() {
1919
}
2020

2121
// Example ID to fetch a specific volume purchasing location
22-
specificID := "1" // Replace with a valid ID
22+
specificID := "13" // Replace with a valid ID
2323

2424
// Example of calling GetVolumePurchasingLocationByID
2525
fmt.Printf("Fetching volume purchasing location with ID %s...\n", specificID)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
8+
)
9+
10+
func main() {
11+
// Define the path to the JSON configuration file
12+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
13+
14+
// Initialize the Jamf Pro client with the HTTP client configuration
15+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
16+
if err != nil {
17+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
18+
}
19+
20+
id := "14" // Replace with the actual ID of the volume purchasing location you want to update
21+
22+
// Create the payload
23+
updatedVPL := &jamfpro.VolumePurchasingLocationCreateUpdateRequest{
24+
Name: "Updated Test VPP Location",
25+
AutomaticallyPopulatePurchasedContent: true,
26+
SendNotificationWhenNoLongerAssigned: false,
27+
AutoRegisterManagedUsers: true,
28+
SiteID: "-1", // Replace with your actual site ID
29+
ServiceToken: "eyJleHBEYXRlIjoiMjAyNi0wNS0w....", // Replace with your actual service token
30+
}
31+
32+
// Print the payload for debugging
33+
fmt.Printf("Sending payload: %+v\n", updatedVPL)
34+
35+
// Call the CreateVolumePurchasingLocation function
36+
response, err := client.UpdateVolumePurchasingLocationByID(id, updatedVPL)
37+
if err != nil {
38+
log.Fatalf("Error updating volume purchasing location: %v", err)
39+
}
40+
41+
// Print the response
42+
fmt.Printf("Updated Volume Purchasing Location: %+v\n", response)
43+
}

sdk/jamfpro/jamfproapi_volume_purchasing_locations.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ type VolumePurchasingSubsetContent struct {
7575
AdamId string `json:"adamId"`
7676
}
7777

78+
// VolumePurchasingLocationCreateUpdateRequest represents the request structure for creating or updating a volume purchasing location.
79+
type VolumePurchasingLocationCreateUpdateRequest struct {
80+
Name string `json:"name,omitempty"`
81+
AutomaticallyPopulatePurchasedContent bool `json:"automaticallyPopulatePurchasedContent"`
82+
SendNotificationWhenNoLongerAssigned bool `json:"sendNotificationWhenNoLongerAssigned"`
83+
AutoRegisterManagedUsers bool `json:"autoRegisterManagedUsers"`
84+
SiteID string `json:"siteId,omitempty"`
85+
ServiceToken string `json:"serviceToken"`
86+
}
87+
7888
// CRUD
7989
// VPP Locations
8090

@@ -117,11 +127,11 @@ func (c *Client) GetVolumePurchasingLocationByID(id string) (*ResourceVolumePurc
117127
}
118128

119129
// CreateVolumePurchasingLocation creates a new volume purchasing location.
120-
func (c *Client) CreateVolumePurchasingLocation(request *ResourceVolumePurchasingLocation) (*ResponseVolumePurchasingLocationCreate, error) {
130+
func (c *Client) CreateVolumePurchasingLocation(request *VolumePurchasingLocationCreateUpdateRequest) (*ResponseVolumePurchasingLocationCreate, error) {
121131
endpoint := uriVolumePurchasingLocations
122132

123-
var response ResponseVolumePurchasingLocationCreate
124-
resp, err := c.HTTP.DoRequest("POST", endpoint, request, &response)
133+
var responseLocation ResponseVolumePurchasingLocationCreate
134+
resp, err := c.HTTP.DoRequest("POST", endpoint, request, &responseLocation)
125135
if err != nil {
126136
return nil, fmt.Errorf("failed to create volume purchasing location: %v", err)
127137
}
@@ -130,16 +140,17 @@ func (c *Client) CreateVolumePurchasingLocation(request *ResourceVolumePurchasin
130140
defer resp.Body.Close()
131141
}
132142

133-
return &response, nil
143+
return &responseLocation, nil
134144
}
135145

136146
// UpdateVolumePurchasingLocationByID updates a specific volume purchasing location by its ID.
137-
func (c *Client) UpdateVolumePurchasingLocationByID(id string) (*ResourceVolumePurchasingLocation, error) {
147+
func (c *Client) UpdateVolumePurchasingLocationByID(id string, request *VolumePurchasingLocationCreateUpdateRequest) (*ResourceVolumePurchasingLocation, error) {
138148
endpoint := fmt.Sprintf("%s/%s", uriVolumePurchasingLocations, id)
149+
139150
var responseLocation ResourceVolumePurchasingLocation
140-
resp, err := c.HTTP.DoRequest("PATCH", endpoint, nil, &responseLocation)
151+
resp, err := c.HTTP.DoRequest("PATCH", endpoint, request, &responseLocation)
141152
if err != nil {
142-
return nil, fmt.Errorf(errMsgFailedGetByID, "vpp locations", id, err)
153+
return nil, fmt.Errorf("failed to update volume purchasing location: %v", err)
143154
}
144155

145156
if resp != nil && resp.Body != nil {
@@ -151,7 +162,7 @@ func (c *Client) UpdateVolumePurchasingLocationByID(id string) (*ResourceVolumeP
151162

152163
// DeleteVolumePurchasingLocationByID deletes a specific volume purchasing location by its ID.
153164
func (c *Client) DeleteVolumePurchasingLocationByID(id string) error {
154-
endpoint := uriVolumePurchasingLocations
165+
endpoint := fmt.Sprintf("%s/%s", uriVolumePurchasingLocations, id)
155166
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
156167
if err != nil {
157168
return fmt.Errorf(errMsgFailedDeleteByID, "vpp location", id, err)

0 commit comments

Comments
 (0)