1. Go to this page and download the library: Download fredbradley/jamf-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fredbradley / jamf-api example snippets
use FredBradley\JamfApi\Facades\Jamf;
$page = Jamf::computerInventory()->list();
use FredBradley\JamfApi\JamfClient;
class DeviceController extends Controller
{
public function __construct(private readonly JamfClient $jamf) {}
public function index(): JsonResponse
{
$page = $this->jamf->computerInventory()->list();
return response()->json($page->results);
}
}
use FredBradley\JamfApi\Facades\Jamf;
$page = Jamf::computerInventory()->list(
page: 0, // zero-based page index
pageSize: 50, // results per page
);
$page->results; // list<ComputerSummary>
$page->totalCount; // int — total records across all pages
$page->totalPages(); // int
$page->hasMorePages(); // bool
$page->nextPage(); // ?int — null on the last page
$page->isFirstPage(); // bool
$page->isLastPage(); // bool
$page->count(); // number of results on this page
$page = 0;
do {
$result = Jamf::mobileDevices()->list(page: $page, pageSize: 100);
foreach ($result->results as $device) {
// $device is a typed MobileDeviceSummary
echo $device->name . ' — ' . $device->serialNumber;
}
$page++;
} while ($result->hasMorePages());
// Find all MacBooks managed by Jamf Pro
$page = Jamf::computerInventory()->list(
filter: 'general.name=="MacBook*"',
sort: ['general.name:asc'],
);
// Find scripts whose name starts with "Deploy"
$page = Jamf::scripts()->list(
filter: 'name=="Deploy*"',
sort: ['name:asc', 'modificationDate:desc'],
);
// Find mobile devices on a specific OS version
$page = Jamf::mobileDevices()->list(
filter: 'osVersion=="18.*"',
);
// Computer prestages
$page = Jamf::computerPrestages()->list();
$prestage = Jamf::computerPrestages()->find('1');
echo $prestage->displayName;
echo $prestage->defaultPrestage ? 'default' : '';
// View scope (assigned serial numbers)
$scope = Jamf::computerPrestages()->scope('1');
// Add devices to scope
Jamf::computerPrestages()->addToScope('1', ['C02XG123ABCD', 'C02XH456EFGH'], $prestage->versionLock);
// Remove from scope
Jamf::computerPrestages()->removeFromScope('1', ['C02XG123ABCD'], $prestage->versionLock);
// Mobile device prestages work the same way
$page = Jamf::mobileDevicePrestages()->list();
Jamf::mobileDevicePrestages()->addToScope('2', ['DLXVF123ABCD'], $versionLock);
// List Apple Business Manager / School Manager connections
$page = Jamf::deviceEnrollments()->list();
// Trigger a sync
Jamf::deviceEnrollments()->sync('1');
// Check latest sync status
$sync = Jamf::deviceEnrollments()->latestSync('1');
// List enrolled devices
$devices = Jamf::deviceEnrollments()->devices('1');
// List available privilege strings
$privileges = Jamf::apiRolePrivileges()->list();
$matches = Jamf::apiRolePrivileges()->search('Read Computers');
// Create an API role
$role = Jamf::apiRoles()->create('Read-Only Access', [
'Read Computers',
'Read Mobile Devices',
'Read Scripts',
]);
// Create an API integration and generate OAuth credentials
$integration = Jamf::apiIntegrations()->create([
'displayName' => 'My Laravel App',
'enabled' => true,
'accessTokenLifetimeSeconds' => 1800,
'apiRoleIds' => [$role->id],
]);
$credentials = Jamf::apiIntegrations()->generateClientCredentials($integration->id);
// $credentials['clientId'] and $credentials['clientSecret'] — store the secret securely, it cannot be retrieved again
// Accept the disclaimer (acceptDisclaimer();
// Enable patch management
Jamf::patchManagement()->save(['enabled' => true]);
// List patchable software titles
$page = Jamf::patchTitles()->list(filter: 'name=="Google Chrome*"');
// Create a patch software title configuration
$config = Jamf::patchSoftwareTitleConfigurations()->create([
'displayName' => 'Google Chrome Updates',
'softwareTitleId' => '42',
'categoryId' => '3',
]);
// View the deployment dashboard
$dashboard = Jamf::patchSoftwareTitleConfigurations()->dashboard($config->id);
// Export a patch report as CSV
$csv = Jamf::patchSoftwareTitleConfigurations()->exportReport($config->id);
// Download the CSV template
$template = Jamf::inventoryPreload()->csvTemplate();
file_put_contents('/tmp/preload-template.csv', $template);
// Import records from CSV
$result = Jamf::inventoryPreload()->importCsv(file_get_contents('/tmp/devices.csv'));
// Manage individual records
$page = Jamf::inventoryPreload()->list();
$record = Jamf::inventoryPreload()->find('1');
Jamf::inventoryPreload()->create([
'serialNumber' => 'C02XG123ABCD',
'deviceType' => 'Computer',
'username' => 'jsmith',
'department' => 'IT',
]);
Jamf::inventoryPreload()->deleteAll(); // remove all preload records
// Get the current local admin password for a device
$result = Jamf::localAdminPassword()->getPassword(
clientManagementId: 'abc-123',
username: 'admin'
);
// Rotate (regenerate) the password
Jamf::localAdminPassword()->rotate('abc-123', 'admin');
// List all LAPS accounts across all devices
$page = Jamf::localAdminPassword()->allAccounts(filter: 'deviceName=="MacBook*"');
use FredBradley\JamfApi\Enums\MdmCommandType;
// Send a blank push to trigger check-in
Jamf::mdm()->send([
'clientManagementIds' => ['device-mgmt-id-1', 'device-mgmt-id-2'],
'commandType' => MdmCommandType::BlankPush->value,
]);
// Lock a device
Jamf::mdm()->send([
'clientManagementIds' => ['device-mgmt-id-1'],
'commandType' => MdmCommandType::DeviceLock->value,
'pin' => '123456', //
// List Apple Business Manager content token connections
$page = Jamf::volumePurchasingLocations()->list();
// Revoke all licenses for a location (e.g. before deleting)
Jamf::volumePurchasingLocations()->revokeLicenses('1');
// Manage VPP event subscriptions
$page = Jamf::volumePurchasingSubscriptions()->list();
Jamf::volumePurchasingSubscriptions()->create([
'name' => 'VPP License Assigned',
'enabled' => true,
]);
// Global history (for resources like departments, buildings)
$history = Jamf::departments()->globalHistory(sort: ['date:desc']);
// Per-record history (for scripts, packages, webhooks, prestages, etc.)
$history = Jamf::scripts()->historyFor('10', pageSize: 50);
$history = Jamf::computerPrestages()->historyFor('1');
$history = Jamf::webhooks()->historyFor('5');
foreach ($history->results as $note) {
// $note is a HistoryNote
echo $note->date . ' — ' . $note->username . ': ' . $note->note;
}
// Add a note
Jamf::scripts()->historyFor('10'); // set current context first
Jamf::scripts()->addHistoryNote('Updated script for macOS Sequoia compatibility');
use FredBradley\JamfApi\Exceptions\NotFoundException;
use FredBradley\JamfApi\Exceptions\JamfException;
use FredBradley\JamfApi\Facades\Jamf;
try {
$computer = Jamf::computerInventory()->find('999');
} catch (NotFoundException $e) {
// Computer does not exist
logger()->warning('Computer not found', ['id' => '999']);
} catch (JamfException $e) {
// Catch-all for any other Jamf API error
logger()->error('Jamf API error', [
'status' => $e->getHttpStatus(),
'errors' => $e->getErrors(),
]);
}