Skip to content

linkvice/php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkVice PHP SDK

Official PHP SDK for the LinkVice Redirect Management API.

Requirements

  • PHP 7.4 or later
  • cURL extension
  • JSON extension

Installation

Install via Composer:

composer require linkvice/php-sdk

Quick Start

<?php

require_once 'vendor/autoload.php';

use LinkVice\LinkVice;

$client = new LinkVice('your-api-key');

// List all domains
$domains = $client->getDomains();
print_r($domains);

Configuration

The constructor accepts three parameters:

Parameter Type Default Description
$apiKey string (required) Your API bearer token
$baseUrl string https://www.linkvice.com/api/v1/ API base URL
$timeout int 30 Request timeout (seconds)
$client = new LinkVice(
    apiKey:  'your-api-key',
    baseUrl: 'https://www.linkvice.com/api/v1/',
    timeout: 60
);

API Reference

Domains

List all domains

$domains = $client->getDomains();

Add a domain

$domain = $client->addDomain('example.com', true);  // domain, useSsl

Get a domain

$domain = $client->getDomain(42);

Delete a domain

$result = $client->deleteDomain(42);

Redirects

List redirects

// All redirects, page 1, 25 per page
$redirects = $client->getRedirects();

// Filter by domain, page 2, 10 per page
$redirects = $client->getRedirects(domainId: 42, page: 2, perPage: 10);

Create a redirect

$redirect = $client->createRedirect([
    'domain_id'     => 42,
    'target_url'    => 'https://www.example.com/destination',
    'redirect_type' => 'permanent',
    'http_code'     => 301,
    'block_bots'    => false,
    'favicon_redirect' => true,
    'robots_redirect'  => false,
    'ads_redirect'     => false,
    'llm_redirect'     => false,
]);

Supported fields:

Field Type Description
domain_id int ID of the domain (required)
target_url string Destination URL (required)
redirect_type string Redirect type (e.g. permanent, temporary)
http_code int HTTP status code (301, 302, etc.)
language_rules array Language-based routing rules
image_redirect_url string Image redirect URL
block_bots bool Block bot traffic
favicon_redirect bool Enable favicon redirect
robots_redirect bool Enable robots.txt redirect
ads_redirect bool Enable ads redirect
llm_redirect bool Enable LLM redirect

Create a redirect with language rules

$redirect = $client->createRedirect([
    'domain_id'      => 42,
    'target_url'     => 'https://www.example.com/en',
    'redirect_type'  => 'permanent',
    'http_code'      => 301,
    'language_rules' => [
        ['language' => 'de', 'target_url' => 'https://www.example.com/de'],
        ['language' => 'fr', 'target_url' => 'https://www.example.com/fr'],
    ],
]);

Get a redirect

$redirect = $client->getRedirect(99);

Update a redirect

$updated = $client->updateRedirect(99, [
    'target_url' => 'https://www.example.com/new-destination',
    'http_code'  => 302,
    'block_bots' => true,
]);

Delete a redirect

$result = $client->deleteRedirect(99);

Statistics

Redirect statistics

$stats = $client->getRedirectStats(99);

// With filters
$stats = $client->getRedirectStats(99, [
    'date_from' => '2025-01-01',
    'date_to'   => '2025-12-31',
    'country'   => 'US',
    'language'  => 'en',
]);

Domain statistics

$stats = $client->getDomainStats(42);

// With filters
$stats = $client->getDomainStats(42, [
    'date_from' => '2025-06-01',
    'date_to'   => '2025-06-30',
]);

Supported filters:

Filter Type Description
date_from string Start date (YYYY-MM-DD)
date_to string End date (YYYY-MM-DD)
country string ISO 3166-1 alpha-2 country code
language string ISO 639-1 language code

Blacklist

List blacklist rules

// All rules
$rules = $client->getBlacklistRules();

// Filter by type: "uri", "ip", or "useragent"
$rules = $client->getBlacklistRules('ip');

Add a blacklist rule

// Exact-match URI rule
$rule = $client->addBlacklistRule('uri', '/spam-path', false, 'Block spam');

// Regex IP rule
$rule = $client->addBlacklistRule('ip', '^10\.0\.0\.\d+$', true, 'Block subnet');

// User-agent rule
$rule = $client->addBlacklistRule('useragent', 'BadBot', false, 'Block BadBot');

Parameters:

Parameter Type Description
$ruleType string uri, ip, or useragent
$pattern string Pattern to match
$isRegex bool true if pattern is a regular expression
$note string/null Optional human-readable note

Delete a blacklist rule

$result = $client->deleteBlacklistRule(15);

Error Handling

The SDK throws two exception types:

  • \RuntimeException -- Network or cURL failures (timeouts, DNS errors, connection refused).
  • \UnexpectedValueException -- API-level errors (authentication failure, validation errors, 404s). The exception code contains the HTTP status code.
try {
    $domains = $client->getDomains();
} catch (\UnexpectedValueException $e) {
    // API returned an error (4xx / 5xx)
    echo "API error (HTTP {$e->getCode()}): {$e->getMessage()}";
} catch (\RuntimeException $e) {
    // Network failure
    echo "Network error: {$e->getMessage()}";
}

Examples

See the examples/basic.php file for a complete walkthrough of every SDK method.

LINKVICE_API_KEY=your-key php examples/basic.php

License

MIT -- see LICENSE for details.

About

Official LinkVice php SDK for redirect management API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages