Skip to content

A free open source IT asset/license management system

Fixed #19738 - honor Jamf Pro filters

snipede8044d7517a
diff --git a/app/SyncAdapters/Jamf/JamfClient.php b/app/SyncAdapters/Jamf/JamfClient.php
index a39fb5b9f4..90e6b0486d 100644
--- a/app/SyncAdapters/Jamf/JamfClient.php
+++ b/app/SyncAdapters/Jamf/JamfClient.php
@@ -48,17 +48,21 @@ class JamfClient
{
$page = 0;
+ // Build the query string by hand so the wire form matches
+ // what Jamf actually reads.
+ $sections = ['GENERAL', 'HARDWARE', 'OPERATING_SYSTEM', 'USER_AND_LOCATION'];
+
do {
+ $query = http_build_query([
+ 'page' => $page,
+ 'page-size' => $pageSize,
+ ]);
+ foreach ($sections as $section) {
+ $query .= '&section=' . urlencode($section);
+ }
+
$response = $this->request()
- ->get('/api/v1/computers-inventory', [
- 'page' => $page,
- 'page-size' => $pageSize,
- // Only the sections we normalize. skipping the
- // heavier ones (applications, plugins, fonts,
- // certificates) keeps payloads small and stays
- // well under Jamf's per-tenant rate limit.
- 'section' => ['GENERAL', 'HARDWARE', 'OPERATING_SYSTEM', 'USER_AND_LOCATION'],
- ])
+ ->get('/api/v1/computers-inventory?' . $query)
->throw()
->json();
diff --git a/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php b/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php
index ca59bf428c..5643339de9 100644
--- a/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php
+++ b/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php
@@ -49,6 +49,24 @@ class JamfAdapterTest extends TestCase
$this->assertDatabaseHas('asset_external_sources', ['source' => 'jamf', 'external_id' => '42']);
$this->assertDatabaseHas('asset_external_sources', ['source' => 'jamf', 'external_id' => '99']);
$this->assertDatabaseHas('assets', ['name' => 'lab-mac-01']);
+
+ // Laravel's default array-shaped query encoding produces the bracketed
+ // form and Jamf silently drops it, leaving every asset with
+ // no hardware section (and no model id). The client hand-builds
+ // the query string to force the API shape Jamf actually reads.
+ Http::assertSent(function ($request) {
+ if (!str_contains($request->url(), '/api/v1/computers-inventory')) {
+ return false;
+ }
+ $url = $request->url();
+
+ return str_contains($url, 'section=GENERAL')
+ && str_contains($url, 'section=HARDWARE')
+ && str_contains($url, 'section=OPERATING_SYSTEM')
+ && str_contains($url, 'section=USER_AND_LOCATION')
+ && !str_contains($url, 'section%5B')
+ && !str_contains($url, 'section[');
+ });
}
public function test_normalized_record_carries_expected_fields()