PHP code example of dimer47 / simplemdm-php-sdk

1. Go to this page and download the library: Download dimer47/simplemdm-php-sdk 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/ */

    

dimer47 / simplemdm-php-sdk example snippets


use SimpleMDM\SimpleMDM;

$mdm = new SimpleMDM('your-api-key');

// List all devices
$devices = $mdm->devices->list();

// Get a specific device
$device = $mdm->devices->get(123);

// Lock a device
$mdm->devices->lock(123, [
    'message' => 'This device has been locked.',
    'phone_number' => '555-0123',
]);

use SimpleMDM\Laravel\Facades\SimpleMDM;

$devices = SimpleMDM::devices->list();
$account = SimpleMDM::account->get();

use SimpleMDM\SimpleMDM;

class DeviceController extends Controller
{
    public function index(SimpleMDM $mdm)
    {
        return $mdm->devices->list();
    }
}

$mdm->account->get();
$mdm->account->update(['name' => 'My Company']);

$mdm->devices->list();
$mdm->devices->get($id);
$mdm->devices->create('Device Name', $groupId);
$mdm->devices->update($id, ['name' => 'New Name']);
$mdm->devices->delete($id);

// Actions
$mdm->devices->lock($id, ['message' => '...', 'phone_number' => '...']);
$mdm->devices->wipe($id);
$mdm->devices->restart($id);
$mdm->devices->shutdown($id);
$mdm->devices->refresh($id);
$mdm->devices->pushApps($id);
$mdm->devices->clearPasscode($id);
$mdm->devices->clearFirmwarePassword($id);
$mdm->devices->clearRestrictionsPassword($id);
$mdm->devices->updateOS($id);

// Firmware & Recovery passwords
$mdm->devices->rotateFirmwarePassword($id);
$mdm->devices->clearRecoveryLockPassword($id);
$mdm->devices->rotateRecoveryLockPassword($id);
$mdm->devices->rotateFileVaultKey($id);

// Admin password
$mdm->devices->setAdminPassword($id, ['password' => '...']);
$mdm->devices->rotateAdminPassword($id);

// Bluetooth & Remote Desktop
$mdm->devices->enableBluetooth($id);
$mdm->devices->disableBluetooth($id);
$mdm->devices->enableRemoteDesktop($id);
$mdm->devices->disableRemoteDesktop($id);

// Related data
$mdm->devices->listInstalledApps($id);
$mdm->devices->listProfiles($id);
$mdm->devices->listUsers($id);
$mdm->devices->deleteUser($deviceId, $userId);

// Custom attributes
$mdm->devices->listCustomAttributes($id);
$mdm->devices->setCustomAttribute($id, 'attribute_name', 'value');
$mdm->devices->setCustomAttributes($id, ['attr1' => 'val1', 'attr2' => 'val2']); // bulk

// Other
$mdm->devices->setTimeZone($id, 'Europe/Paris');
$mdm->devices->unenroll($id);

$mdm->apps->list();
$mdm->apps->get($id);
$mdm->apps->create('/path/to/app.ipa', 'App Name');           // Upload binary
$mdm->apps->createFromAppStore('899247664', 'App Name');       // From App Store ID
$mdm->apps->createFromBundleId('com.example.app', 'App Name'); // From Bundle ID
$mdm->apps->update($id, ['name' => 'Updated Name']);
$mdm->apps->delete($id);

// Munki
$mdm->apps->uploadMunkiPkgInfo($id, '/path/to/pkginfo.plist');
$mdm->apps->deleteMunkiPkgInfo($id);

$mdm->assignmentGroups->list();
$mdm->assignmentGroups->get($id);
$mdm->assignmentGroups->create('Group Name');
$mdm->assignmentGroups->update($id, ['name' => 'New Name']);
$mdm->assignmentGroups->delete($id);

// Apps
$mdm->assignmentGroups->assignApp($groupId, $appId);
$mdm->assignmentGroups->unassignApp($groupId, $appId);
$mdm->assignmentGroups->pushApps($id);
$mdm->assignmentGroups->updateApps($id);

// Devices
$mdm->assignmentGroups->assignDevice($groupId, $deviceId);
$mdm->assignmentGroups->unassignDevice($groupId, $deviceId);

// Device Groups
$mdm->assignmentGroups->assignDeviceGroup($groupId, $deviceGroupId);
$mdm->assignmentGroups->unassignDeviceGroup($groupId, $deviceGroupId);

// Profiles
$mdm->assignmentGroups->assignProfile($groupId, $profileId);
$mdm->assignmentGroups->unassignProfile($groupId, $profileId);
$mdm->assignmentGroups->syncProfiles($id);

// Other
$mdm->assignmentGroups->clone($id);
$mdm->assignmentGroups->getCustomAttributes($id);
$mdm->assignmentGroups->setCustomAttribute($id, 'attr_name', 'value');

$mdm->customAttributes->list();
$mdm->customAttributes->get($id);
$mdm->customAttributes->create('Attribute Name', 'default_value');
$mdm->customAttributes->update($id, ['name' => 'New Name']);
$mdm->customAttributes->delete($id);

$mdm->customConfigurationProfiles->list();
$mdm->customConfigurationProfiles->get($id);
$mdm->customConfigurationProfiles->create('/path/to/profile.mobileconfig');
$mdm->customConfigurationProfiles->update($id, ['name' => 'New Name']);
$mdm->customConfigurationProfiles->delete($id);
$mdm->customConfigurationProfiles->download($id);

// Per-device assignment
$mdm->customConfigurationProfiles->pushToDevice($profileId, $deviceId);
$mdm->customConfigurationProfiles->removeFromDevice($profileId, $deviceId);

// Device group assignment
$mdm->customConfigurationProfiles->assignToDeviceGroup($profileId, $deviceGroupId);
$mdm->customConfigurationProfiles->unassignFromDeviceGroup($profileId, $deviceGroupId);

$mdm->customDeclarations->list();
$mdm->customDeclarations->get($id);
$mdm->customDeclarations->create('com.apple.configuration.management.test', '/path/to/payload.json', 'Declaration Name');
$mdm->customDeclarations->update($id, ['name' => 'New Name']);
$mdm->customDeclarations->delete($id);
$mdm->customDeclarations->download($id);

// Per-device
$mdm->customDeclarations->pushToDevice($declarationId, $deviceId);
$mdm->customDeclarations->removeFromDevice($declarationId, $deviceId);

$mdm->depServers->list();
$mdm->depServers->get($id);
$mdm->depServers->listDevices($id);
$mdm->depServers->getDevice($serverId, $depDeviceId);
$mdm->depServers->sync($id);

$mdm->enrollments->list();
$mdm->enrollments->get($id);
$mdm->enrollments->delete($id);
$mdm->enrollments->sendInvitation($id, '[email protected]');

$mdm->installedApps->get($id);
$mdm->installedApps->update($id);
$mdm->installedApps->delete($id);

$mdm->logs->list(['namespace' => 'device']);
$mdm->logs->get($id);

$mdm->lostMode->enable($deviceId, [
    'message' => 'Please return this device.',
    'phone_number' => '555-0123',
]);
$mdm->lostMode->disable($deviceId);
$mdm->lostMode->playSound($deviceId);
$mdm->lostMode->updateLocation($deviceId);

$mdm->managedAppConfigs->list($appId);
$mdm->managedAppConfigs->create($appId, 'config_key', 'config_value', 'string');
$mdm->managedAppConfigs->push($appId);
$mdm->managedAppConfigs->delete($appId, $configId);
$mdm->managedAppConfigs->deleteAll($appId);

$mdm->profiles->list();
$mdm->profiles->get($id);
$mdm->profiles->assignToDevice($profileId, $deviceId);
$mdm->profiles->unassignFromDevice($profileId, $deviceId);
$mdm->profiles->assignToDeviceGroup($profileId, $deviceGroupId);
$mdm->profiles->unassignFromDeviceGroup($profileId, $deviceGroupId);

$mdm->pushCertificate->get();
$mdm->pushCertificate->update('/path/to/cert.pem', '[email protected]');
$mdm->pushCertificate->getSignedCsr();

$mdm->scripts->list();
$mdm->scripts->get($id);
$mdm->scripts->create('Script Name', '/path/to/script.sh', variableSupport: true);
$mdm->scripts->update($id, ['name' => 'New Name']);
$mdm->scripts->delete($id);

$mdm->scriptJobs->list();
$mdm->scriptJobs->get($id);
$mdm->scriptJobs->create($scriptId, [
    'device_ids' => [1, 2, 3],
    'assignment_group_ids' => [10],
]);
$mdm->scriptJobs->cancel($id);

use SimpleMDM\Exceptions\ApiException;
use SimpleMDM\Exceptions\AuthenticationException;
use SimpleMDM\Exceptions\RateLimitException;

try {
    $devices = $mdm->devices->list();
} catch (AuthenticationException $e) {
    // Invalid API key (401)
} catch (RateLimitException $e) {
    // Too many requests (429)
    $retryAfter = $e->getRetryAfter(); // seconds until rate limit resets
} catch (ApiException $e) {
    // Other API error
    $statusCode = $e->getStatusCode();
    $responseBody = $e->getResponseBody();
}
bash
composer 
bash
php artisan vendor:publish --tag=simplemdm-config