1. Go to this page and download the library: Download coyshdigital/beaconcrm-php 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/ */
$beacon = BeaconClient::make(getenv('BEACON_ACCOUNT_ID'), getenv('BEACON_API_KEY'));
if (!$beacon->ping()) {
// Wrong account ID, or the key was revoked or mistyped.
}
use CoyshDigital\Beacon\Exception\InvalidPayloadException;
try {
$people->upsert('emails', $people->payload()->set('c_tier', 'Gold'));
} catch (InvalidPayloadException $e) {
// Upsert key "emails" has no value in the person payload...
}
$response = $people->list(page: 1, perPage: 100, populate: false);
$response->total(); // 39713, the whole match count rather than the page
$response->entities(); // the records, unwrapped
// One request. Matches on the field, and creates the record if nothing matches.
$orgId = $organisations->resolveId('name', $organisations->payload()->set('name', $church));
// Pages the whole record type and compares client-side. Never creates.
$org = $organisations->findBy('name', $church);
$exportId = $beacon->exports()->trigger($templateId)->entity()['id'] ?? null;
$status = $beacon->exports()->status($exportId)->results()[0] ?? [];
$status['status']; // in_progress or finished
$status['progress']; // 0 to 100
$people->payload()
->set('address:address_line_one', '12 Example Street')
->set('address:city', 'Warwick')
->set('address:postal_code', 'CV34 4AB');
use CoyshDigital\Beacon\Exception\ApiException;
try {
$people->create($payload);
} catch (ApiException $e) {
$e->getStatus(); // 500
$e->getErrorCode(); // server_error
$e->getMessage(); // Oh shoot! An unknown error occurred.
$e->getRaw(); // Validation error: "gender": 0 Invalid option.
// Allowed options: Male, Female, Non-binary, ...
$e->getPayload(); // what was sent, credentials redacted
$e->getSummary(); // all of the above on one line, for a log
}
use CoyshDigital\Beacon\Http\RetryPolicy;
$beacon = BeaconClient::make($accountId, $apiKey, new RetryPolicy(
maxAttempts: 5,
baseDelayMs: 1000,
));
// Or turn retries off and handle them yourself.
$beacon = BeaconClient::make($accountId, $apiKey, RetryPolicy::none());
$request = $people->createRequest($payload);
$request->method; // POST
$request->path; // entity/person
$request->uri(); // entity/person?populate=false
$request->body; // the shaped entity