PHP code example of lix-url / php-sdk
1. Go to this page and download the library: Download lix-url/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/ */
lix-url / php-sdk example snippets
use Lix\Client;
$client = new Client('lix_live_xxx');
$link = $client->links()->create('https://example.com');
echo $link->link->shortUrl;
$profile = $client->profile()->get();
echo $profile->user->email;
$link = $client->links()->create(
url: 'https://example.com'
);
echo $link->link->shortUrl;
$link = $client->links()->create(
url: 'https://example.com',
alias: 'my-link'
);
$link = $client->links()->create(
url: 'https://example.com',
utm: [
'source' => 'newsletter',
'medium' => 'email',
'campaign' => 'summer-sale',
]
);
$link = $client->links()->get(123);
echo $link->url;
echo $link->shortUrl;
$link = $client->links()->update(
id: 123,
title: 'Updated title'
);
$client->links()->delete(123);
$linksResponse = $client->links()->list();
foreach ($linksResponse->links as $link) {
echo $link->shortUrl . PHP_EOL;
}
$links = $client->links()->list(
limit: 100,
fromId: 500
);
$group = $client->groups()->create(
name: 'Marketing'
);
echo $group->name;
$group = $client->groups()->create(
name: 'Landing Pages',
isRotate: true
);
$group = $client->groups()->get(10);
$group = $client->groups()->update(
groupId: 10,
description: 'Updated description'
);
$client->groups()->delete(10);
$response = $client->groups()->list(limit: 10, fromId: 1000);
foreach ($response->groups as $group) {
echo $group->name . PHP_EOL;
}
use Lix\Exceptions\UnauthorizedException;
use Lix\Exceptions\ValidationException;
try {
$client->links()->create(
url: 'invalid-url'
);
} catch (ValidationException $e) {
// Validation failed
// Validation error fields data
var_dump($e->data);
} catch (UnauthorizedException $e) {
// Invalid API key
}