PHP code example of fw4 / mason-api

1. Go to this page and download the library: Download fw4/mason-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/ */

    

fw4 / mason-api example snippets


use Mason\Api\Client;

$api = new Client('client-id', 'client-secret');
$group = $api->group(123);

$group->estates->list($parameters);
$group->estates->offline($parameters);
$group->estates->get('estate-id');
$group->estates->setPublicUrl('estate-id', 'public-url');

$group->previews->list($parameters);

$group->offices->list();

$group->webhook->set('webhook-url');
$group->webhook->unset();

$group->sendContactRequest($parameters);
$group->sendValuationRequest($parameters);

$api->token->info();
$api->token->revoke();

$estates = $group->estates->list();

// Traversing over the response takes care of pagination in the background
foreach ($estates as $estate) {
    echo $estate->name . PHP_EOL;
}

$page_index = 3;
$items_per_page = 20;

$estates = $group->estates->list([
    'updated_since' => new \DateTime('2026-01-01')
]);
$page = $estates->page($page_index, $items_per_page);

echo 'Showing ' . $page->count() . ' items out of ' . $page->getTotalCount() . PHP_EOL;
echo 'Page ' . $page->getPage() . ' of ' . $page->getPageCount() . PHP_EOL;
foreach ($page as $estate) {
    echo $estate->name . PHP_EOL;
}

$api = new Client(
    clientId: 'client-id',
    clientSecret: 'client-secret',
    baseUrl: 'https://api.example.com/',
);

$api = new Client(
    clientId: 'client-id',
    clientSecret: 'client-secret',
    defaultPageSize: 100,
);

use Mason\Api\Auth\TokenStorage\FileTokenStorage;

$api = new Client(
    clientId: 'client-id',
    clientSecret: 'client-secret',
    tokenStorage: new FileTokenStorage('/secure/cache/mason-api'),
);

use Mason\Api\Auth\TokenStorage\RedisTokenStorage;

$redis = new Redis();
$redis->connect('127.0.0.1');

$api = new Client(
    clientId: 'client-id',
    clientSecret: 'client-secret',
    tokenStorage: new RedisTokenStorage($redis),
);