Skip to content

lix-url/php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lix.li PHP SDK

Official PHP SDK for the Lix.li API.

Lix.li is a URL shortening and link analytics platform with support for custom aliases, groups, tags, UTM parameters and detailed click tracking.

Requirements

  • PHP 8.2+
  • Composer

Installation

composer require lix-url/php-sdk

Quick Start

use Lix\Client;

$client = new Client('lix_live_xxx');
$link = $client->links()->create('https://example.com');
echo $link->link->shortUrl;

Profile

Get information about the authenticated account.

$profile = $client->profile()->get();

echo $profile->user->email;

Links

Create a Link

$link = $client->links()->create(
    url: 'https://example.com'
);

echo $link->link->shortUrl;

Create a Link with Custom Alias

$link = $client->links()->create(
    url: 'https://example.com',
    alias: 'my-link'
);

Create a Link with UTM Parameters

$link = $client->links()->create(
    url: 'https://example.com',
    utm: [
        'source' => 'newsletter',
        'medium' => 'email',
        'campaign' => 'summer-sale',
    ]
);

Get a Link

$link = $client->links()->get(123);

echo $link->url;
echo $link->shortUrl;

Update a Link

$link = $client->links()->update(
    id: 123,
    title: 'Updated title'
);

Delete a Link

$client->links()->delete(123);

List Links

$linksResponse = $client->links()->list();

foreach ($linksResponse->links as $link) {
    echo $link->shortUrl . PHP_EOL;
}

Pagination

$links = $client->links()->list(
    limit: 100,
    fromId: 500
);

Groups

Create a Group

$group = $client->groups()->create(
    name: 'Marketing'
);

echo $group->name;

Create a Rotating Group

$group = $client->groups()->create(
    name: 'Landing Pages',
    isRotate: true
);

Get a Group

$group = $client->groups()->get(10);

Update a Group

$group = $client->groups()->update(
    groupId: 10,
    description: 'Updated description'
);

Delete a Group

$client->groups()->delete(10);

List Groups

$response = $client->groups()->list(limit: 10, fromId: 1000);

foreach ($response->groups as $group) {
    echo $group->name . PHP_EOL;
}

Error Handling

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
}

Documentation

Other SDKs

Support

Need help with the API or SDK?

License

MIT

About

Official PHP SDK for the Lix.li URL shortening and link analytics API.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages