1. Go to this page and download the library: Download rlnks/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/ */
rlnks / sdk example snippets
lnks\Client;
// Initialize the client with your API key
$client = new Client('rlnks_your_api_key');
// List your decision trees
$trees = $client->trees->list();
foreach ($trees as $tree) {
echo $tree->name . ' - ' . $tree->getImageUrl() . "\n";
}
// API keys start with 'rlnks_'
$client = new Client('rlnks_your_api_key');
// You can also specify custom options
$client = new Client('rlnks_your_api_key', [
'base_url' => 'https://app.rlnks.com/api/v1', // Custom base URL
'timeout' => 30, // Request timeout in seconds
'connect_timeout' => 10, // Connection timeout
]);
// List all trees
$trees = $client->trees->list();
// Filter by type
$imageTrees = $client->trees->list(['type' => 'image']);
$redirectTrees = $client->trees->list(['type' => 'redirect']);
// Filter by status
$activeTrees = $client->trees->list(['status' => 'active']);
// Search and pagination
$trees = $client->trees->list([
'search' => 'campaign',
'sort_by' => 'name',
'sort_dir' => 'asc',
'per_page' => 50,
'page' => 1,
]);
// Iterate through results
foreach ($trees as $tree) {
echo "{$tree->name}: {$tree->total_requests} requests\n";
}
// Check pagination
if ($trees->hasNextPage()) {
echo "More trees available...\n";
}
use Rlnks\Webhook\SignatureVerifier;
use Rlnks\Webhook\WebhookEvent;
$verifier = new SignatureVerifier('your_webhook_secret');
// Get the raw payload and headers
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_RLNKS_SIGNATURE'] ?? '';
$timestamp = $_SERVER['HTTP_X_RLNKS_TIMESTAMP'] ?? '';
try {
// Verify and parse the webhook
$data = $verifier->verifyAndParse($payload, $signature, $timestamp);
// Create an event object for easier handling
$event = WebhookEvent::fromPayload($data);
// Handle different event types
switch ($event->getEventType()) {
case WebhookEvent::TREE_CREATED:
echo "Tree created: " . $event->getTreeName();
break;
case WebhookEvent::TREE_UPDATED:
echo "Tree updated: " . $event->getTreeId();
break;
case WebhookEvent::USAGE_LIMIT_WARNING:
echo "Usage warning! Current: " . $event->get('current_usage');
break;
case WebhookEvent::USAGE_LIMIT_REACHED:
echo "Usage limit reached!";
break;
}
// Check event categories
if ($event->isTreeEvent()) {
// Handle all tree events
}
if ($event->isUsageEvent()) {
// Handle usage alerts
}
http_response_code(200);
} catch (\Rlnks\Exceptions\RlnksException $e) {
// Invalid signature or payload
http_response_code(401);
echo "Webhook verification failed: " . $e->getMessage();
}
$domains = $client->customDomains->list();
foreach ($domains as $domain) {
echo "{$domain->domain}: {$domain->getStatusDescription()}\n";
}
// Get only active domains
$activeDomains = $client->customDomains->getActive();
// Get pending domains (awaiting verification or SSL)
$pendingDomains = $client->customDomains->getPending();
// Add a new custom domain
$domain = $client->customDomains->create('links.example.com');
// Get DNS setup instructions
$instructions = $client->customDomains->getDnsInstructions($domain->id);
echo "CNAME Target: " . $instructions['cname_target'] . "\n";
echo "TXT Record Name: " . $instructions['txt_record_name'] . "\n";
echo "TXT Record Value: " . $instructions['txt_record_value'] . "\n";
// Or create with instructions in one call
$result = $client->customDomains->createWithInstructions('links.example.com');
$domain = $result['domain'];
$instructions = $result['dns'];
// After configuring DNS records, verify the domain
$domain = $client->customDomains->verify($domainId);
// Check status
if ($domain->isActive()) {
echo "Domain is active and ready to use!\n";
} elseif ($domain->isPendingSsl()) {
echo "SSL certificate is being provisioned...\n";
} elseif ($domain->hasSslError()) {
// Retry SSL provisioning
$domain = $client->customDomains->retrySsl($domainId);
}
// Set as default for all trees
$client->customDomains->setDefault($domainId);
// Remove from defaults
$client->customDomains->unsetDefault($domainId);
// Get current default
$default = $client->customDomains->getDefault();
if ($client->customDomains->checkAvailability('links.example.com')) {
echo "Domain is available!\n";
}
$link = $client->ephemeralLinks->createImageLink($treeId);
// Test different conditions using the slug
echo $link->getUrlWithSlug('logo'); // /test/i/{uuid}/logo
echo $link->getUrlWithSlug('banner'); // /test/i/{uuid}/banner
echo $link->getUrlWithSlug('header'); // /test/i/{uuid}/header
// The slug is available in tree conditions as 'slug' field:
// - slug equals "logo" -> Show logo image
// - slug equals "banner" -> Show banner image
// List active links for a tree
$links = $client->ephemeralLinks->list($treeId);
// Include expired links
$allLinks = $client->ephemeralLinks->list($treeId, ['linkUuid);
// Delete a link
$client->ephemeralLinks->delete($linkUuid);
// Clean up expired links
$deletedCount = $client->ephemeralLinks->deleteExpired($treeId);
echo "Deleted {$deletedCount} expired links\n";
$link = $client->ephemeralLinks->get($linkUuid);
// Check status
$link->isValid(); // Still usable?
$link->isExpired(); // Time expired?
$link->hasUseLimit(); // Has max uses?
// Usage info
$link->use_count; // Current uses
$link->getRemainingUses(); // Uses left (null if unlimited)
$link->getRemainingTime(); // "5 minutes from now"
// Type
$link->isImageLink(); // true/false
$link->isRedirectLink(); // true/false