Skip to content

Commit 5199c4e

Browse files
authored
feat!: Pagination func filter passing refactored (#760)
* feat: pagination uses proper url formatting now * pagination endpoint change * encode before put in string * handling if no values provided * re add actual paging * added overrrides * debugging * to pointer * debugging * debugging * debugging * debuggng * Reworked paging params * func comment * a comment * new line * vars foramtting standardised * error messages * one lined the func name * removed debug prints * removed unnecessary constants * renamed paginated response model * empty type -> nil * Added md and comments directing to it re url.Values usage
1 parent 67e04e1 commit 5199c4e

File tree

69 files changed

+384
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+384
-296
lines changed

docs/url_queries.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Querying the Jamf Pro API with RSQL
2+
3+
Jamf Pro's **Jamf Pro API (v1+)** supports querying resources using **RSQL filters** via HTTP requests. This guide explains how to construct API queries using URLs with RSQL in Go.
4+
5+
6+
## 📘 Basic URL Format
7+
8+
Jamf Pro API endpoints follow this pattern:
9+
10+
```
11+
https://<jamf-host>/api/<resource-path>?page=0&page-size=50&sort=fieldName:asc&filter=<rsql-expression>
12+
```
13+
14+
- `page`: zero-based page index.
15+
- `page-size`: number of results per page.
16+
- `sort`: optional; `fieldName:asc` or `fieldName:desc`.
17+
- `filter`: your RSQL query string (URL-encoded).
18+
19+
---
20+
21+
## 🔍 Example: Query Computers by Name
22+
23+
**Goal:** Find all computers whose name contains `test`.
24+
25+
**Endpoint:**
26+
27+
```
28+
GET /api/v1/computers-inventory
29+
```
30+
31+
**RSQL Filter:**
32+
33+
```
34+
general.name==*test*
35+
```
36+
37+
**Full URL (URL-encoded):**
38+
39+
```
40+
https://your-jamf-url.com/api/v1/computers-inventory?filter=general.name%3D%3D%2Atest%2A
41+
```
42+
43+
44+
45+
## 🧑‍💻 Creating an RSQL Query using `url.Values{}` in Go
46+
47+
```go
48+
import (
49+
"net/http"
50+
"net/url"
51+
)
52+
53+
func buildJamfQuery() (*http.Request, error) {
54+
baseURL := "https://your-jamf-url.com/api/v1/computers-inventory"
55+
56+
params := url.Values{}
57+
params.Set("page", "0")
58+
params.Set("page-size", "50")
59+
params.Set("sort", "general.name:asc")
60+
params.Set("filter", `general.name==*test*`)
61+
62+
fullURL := baseURL + "?" + params.Encode()
63+
64+
req, err := http.NewRequest("GET", fullURL, nil)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
70+
return req, nil
71+
}
72+
```
73+
74+
- `url.Values{}.Encode()` handles correct URL encoding for you.
75+
- The RSQL filter will be encoded automatically (e.g. `==``%3D%3D`, `*``%2A`).
76+
77+
---

examples/bookmarks/GetBookmarks/GetBookmarks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -18,8 +19,10 @@ func main() {
1819
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
1920
}
2021

22+
// For more information on how to add parameters to this request, see docs/url_queries.md
23+
2124
// Call function
22-
bookmarksList, err := client.GetBookmarks("")
25+
bookmarksList, err := client.GetBookmarks(url.Values{})
2326
if err != nil {
2427
log.Fatalf("Error fetching accounts: %v", err)
2528
}

examples/buildings/GetBuildingResourceHistoryByID/GetBuildingResourceHistoryByID.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"log"
6+
"net/url"
67

78
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
89
)
@@ -18,8 +19,9 @@ func main() {
1819
}
1920

2021
// Example: Fetch the resource history of a building by ID
22+
// For more information on how to add parameters to this request, see docs/url_queries.md
2123
buildingID := "" // Replace with a real building ID
22-
history, err := client.GetBuildingResourceHistoryByID(buildingID, "")
24+
history, err := client.GetBuildingResourceHistoryByID(buildingID, url.Values{})
2325
if err != nil {
2426
log.Fatalf("Error fetching building resource history: %v", err)
2527
}

examples/buildings/GetBuildings/GetBuildings.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -18,8 +19,10 @@ func main() {
1819
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
1920
}
2021

22+
// For more information on how to add parameters to this request, see docs/url_queries.md
23+
2124
// Call GetBuildings function
22-
accountsList, err := client.GetBuildings("")
25+
accountsList, err := client.GetBuildings(url.Values{})
2326
if err != nil {
2427
log.Fatalf("Error fetching accounts: %v", err)
2528
}

examples/categories/GetCategories/GetCategories.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"log"
6+
"net/url"
67

78
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
89
)
@@ -18,9 +19,10 @@ func main() {
1819
}
1920

2021
// Define the sort and filter query parameters
21-
// none
22+
// For more information on how to add parameters to this request, see docs/url_queries.md
23+
2224
// Call the GetCategories function
23-
categories, err := client.GetCategories("") // Will return all results by default
25+
categories, err := client.GetCategories(url.Values{}) // Will return all results by default
2426
if err != nil {
2527
fmt.Printf("Error fetching categories: %v\n", err)
2628
return

examples/cloud_idp/GetCloudIdentityProviders/GetCloudIdentityProviders.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,10 +20,11 @@ func main() {
1920
}
2021

2122
// Optional: Define sort filter (e.g., "id:asc" or "displayName:desc")
22-
sortFilter := "id:desc"
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
params := url.Values{}
2325

2426
// Call GetCloudIdentityProviders function
25-
cloudIdps, err := client.GetCloudIdentityProviders(sortFilter)
27+
cloudIdps, err := client.GetCloudIdentityProviders(params)
2628
if err != nil {
2729
log.Fatalf("Error fetching cloud identity providers: %v", err)
2830
}

examples/computer_extension_attributes/GetComputerExtensionAttributes/GetComputerExtensionAttributes.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/xml"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,7 +20,8 @@ func main() {
1920
}
2021

2122
// Call GetComputerExtensionAttributes function
22-
attributes, err := client.GetComputerExtensionAttributes("")
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
attributes, err := client.GetComputerExtensionAttributes(url.Values{})
2325
if err != nil {
2426
log.Fatalf("Error fetching Computer Extension Attributes: %v", err)
2527
}

examples/computer_inventory/GetComputersFileVaultInventory/GetComputersFileVaultInventory.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,10 +20,12 @@ func main() {
1920
}
2021

2122
// Sort filter
22-
sortFilter := "sort=id:desc"
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
params := url.Values{}
25+
params.Add("sort", "id:desc")
2326

2427
// Call the GetComputersFileVaultInventory function
25-
fileVaultInventory, err := client.GetComputersFileVaultInventory(sortFilter)
28+
fileVaultInventory, err := client.GetComputersFileVaultInventory(params)
2629
if err != nil {
2730
log.Fatalf("Error fetching FileVault inventory: %v", err)
2831
}

examples/computer_inventory/GetComputersInventory/GetComputersInventory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -36,7 +37,8 @@ func main() {
3637
// sections := []string{"GENERAL", "DISK_ENCRYPTION", "STORAGE"} // Example sections
3738

3839
// Call the GetComputersInventory function
39-
inventoryList, err := client.GetComputersInventory("")
40+
// For more information on how to add parameters to this request, see docs/url_queries.md
41+
inventoryList, err := client.GetComputersInventory(url.Values{})
4042
if err != nil {
4143
log.Fatalf("Error fetching computer inventory: %v", err)
4244
}

examples/computer_prestages/GetComputerPrestages/GetComputerPrestages.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,10 +20,12 @@ func main() {
1920
}
2021

2122
// Define sorting parameters
22-
sortFilter := "name" // Example: "name" for sorting by name
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
params := url.Values{}
25+
params.Add("sort", "name")
2326

2427
// Fetch computer prestages using the V3 API
25-
prestages, err := client.GetComputerPrestages(sortFilter)
28+
prestages, err := client.GetComputerPrestages(params)
2629
if err != nil {
2730
log.Fatalf("Error fetching computer prestages: %v", err)
2831
}

examples/departments/DeleteAllDepartments/DeleteAllDepartments.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"log"
6+
"net/url"
67

78
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
89
)
@@ -18,7 +19,8 @@ func main() {
1819
}
1920

2021
// Fetch all departments
21-
departments, err := client.GetDepartments("")
22+
// For more information on how to add parameters to this request, see docs/url_queries.md
23+
departments, err := client.GetDepartments(url.Values{})
2224
if err != nil {
2325
log.Fatalf("Error fetching departments: %v", err)
2426
}

examples/departments/GetDepartments/GetDepartments.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,7 +20,8 @@ func main() {
1920
}
2021

2122
// Call GetDepartments function
22-
departments, err := client.GetDepartments("")
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
departments, err := client.GetDepartments(url.Values{})
2325
if err != nil {
2426
log.Fatalf("Error fetching departments: %v", err)
2527
}

examples/device_enrollments/GetDeviceEnrollmentHistory/GetDeviceEnrollmentHistory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,8 +20,9 @@ func main() {
1920
}
2021

2122
// Fetch Device Enrollment History
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
2224
deviceEnrollmentID := "1" // Using the known device enrollment ID from the system
23-
response, err := client.GetDeviceEnrollmentHistory(deviceEnrollmentID, "")
25+
response, err := client.GetDeviceEnrollmentHistory(deviceEnrollmentID, url.Values{})
2426
if err != nil {
2527
log.Fatalf("Error fetching device enrollment history: %v", err)
2628
}

examples/device_enrollments/GetDeviceEnrollments/GetDeviceEnrollments.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,7 +20,8 @@ func main() {
1920
}
2021

2122
// Fetch Device Enrollments
22-
response, err := client.GetDeviceEnrollments("")
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
response, err := client.GetDeviceEnrollments(url.Values{})
2325
if err != nil {
2426
log.Fatalf("Error fetching Device enrollment instances: %v", err)
2527
}

examples/enrollment/GetAccountDrivenUserEnrollmentAccessGroups/GetAccountDrivenUserEnrollmentAccessGroups.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -19,7 +20,8 @@ func main() {
1920
}
2021

2122
// Call GetAccountDrivenUserEnrollmentAccessGroups function
22-
ADUEAccessGroups, err := client.GetAccountDrivenUserEnrollmentAccessGroups("")
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
ADUEAccessGroups, err := client.GetAccountDrivenUserEnrollmentAccessGroups(url.Values{})
2325
if err != nil {
2426
log.Fatalf("Error fetching ADUE Access Groups: %v", err)
2527
}

examples/enrollment/GetEnrollmentHistory/GetEnrollmentHistory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -20,7 +21,8 @@ func main() {
2021

2122
// Call GetEnrollmentHistory function
2223
// You can add sorting parameters like "sort=date:desc" to sort by date in descending order
23-
history, err := client.GetEnrollmentHistory("")
24+
// For more information on how to add parameters to this request, see docs/url_queries.md
25+
history, err := client.GetEnrollmentHistory(url.Values{})
2426
if err != nil {
2527
log.Fatalf("Error getting enrollment history: %v", err)
2628
}

examples/enrollment_customizations/GetEnrollmentCustomizations/GetEnrollmentCustomizations.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"net/url"
78

89
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
910
)
@@ -18,13 +19,9 @@ func main() {
1819
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
1920
}
2021

21-
// Optional: Define sort and filter parameters
22-
// Example: sort=displayName:asc
23-
// Leave empty string "" for no sorting/filtering
24-
sortFilter := ""
25-
2622
// Get all enrollment customizations
27-
customizations, err := client.GetEnrollmentCustomizations(sortFilter)
23+
// For more information on how to add parameters to this request, see docs/url_queries.md
24+
customizations, err := client.GetEnrollmentCustomizations(url.Values{})
2825
if err != nil {
2926
log.Fatalf("Failed to get enrollment customizations: %v", err)
3027
}

0 commit comments

Comments
 (0)