PHP code example of luizsilva-dev / cj-sdk-php
1. Go to this page and download the library: Download luizsilva-dev/cj-sdk-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/ */
luizsilva-dev / cj-sdk-php example snippets
CJAffiliate\CJClient;
$client = new CJClient([
'access_token' => 'your_personal_access_token',
'publisher_id' => 'your_publisher_id',
'timeout' => 30, // Optional: Request timeout in seconds
'cache_enabled' => true, // Optional: Enable caching
'cache_ttl' => 3600, // Optional: Cache TTL in seconds
'debug' => false // Optional: Enable debug mode
]);
// Search for affiliate links (search([
'website_id' => 'your_website_id',
'advertiser_ids' => '123456', // Optional: specific advertiser
'keywords' => 'knee brace', // Optional: search keywords
'records_per_page' => 10
]);
// Display results
echo "Total links found: " . $links['total_matched'] . "\n";
foreach ($links['links'] as $link) {
echo "- {$link['link_name']}\n";
echo " Advertiser: {$link['advertiser_name']}\n";
echo " Commission: {$link['sale_commission']}\n";
echo " Click URL: {$link['click_url']}\n";
echo "\n";
}
$links = $client->products()->search([
'website_id' => 'your_website_id', // REQUIRED
'advertiser_ids' => '123456,789012', // Optional: comma-separated IDs
'keywords' => 'search terms', // Optional
'link_type' => 'Text Link', // Optional: Banner, Text Link, etc.
'promotion_type' => 'Coupon', // Optional
'records_per_page' => 50, // Optional: default 50, max 1000
'page_number' => 1 // Optional: default 1
]);
[
'links' => [
[
'link_id' => '14496605',
'link_name' => 'Homepage',
'link_type' => 'Text Link',
'advertiser_id' => '123456',
'advertiser_name' => 'BraceAbility',
'destination' => 'https://www.braceability.com',
'click_url' => 'https://www.anrdoezrs.net/click-...',
'description' => 'Homepage',
'sale_commission' => '8.00%',
'seven_day_epc' => '8.99',
'three_month_epc' => '5.59',
'promotion_type' => 'N/A',
'coupon_code' => '',
'category' => 'Equipment',
'relationship_status' => 'joined',
// ... more fields
]
],
'total_matched' => 45,
'records_returned' => 10,
'page_number' => 1
]
// Search all joined advertisers
$advertisers = $client->advertisers()->search([
'advertiser-ids' => 'joined' // or 'notjoined', or specific IDs
]);
// Search by specific advertiser ID
$advertiser = $client->advertisers()->getById('123456');
// Search by name or program URL
$advertisers = $client->advertisers()->getByName('Nike');
// Search by keywords
$advertisers = $client->advertisers()->getByKeywords('shoes fitness');
// Get only joined advertisers
$joined = $client->advertisers()->getJoined();
// Get not joined advertisers
$notJoined = $client->advertisers()->getNotJoined();
[
'advertisers' => [
[
'advertiser_id' => '123456',
'advertiser_name' => 'BraceAbility',
'program_url' => 'https://www.braceability.com',
'relationship_status' => 'joined',
'network_rank' => 3,
'seven_day_epc' => 29.43,
'three_month_epc' => 22.79,
'actions' => [
[
'name' => 'braceability.com Purchase',
'type' => 'advanced sale',
'commission' => ['default' => '8.00%']
]
]
]
],
'total_matched' => 1,
'records_returned' => 1,
'page_number' => 1
]
// Get publisher commissions (last 7 days)
$commissions = $client->commissions()->getPublisherCommissions([
'since_date' => '2025-11-01T00:00:00Z',
'before_date' => '2025-11-15T00:00:00Z'
]);
// Note: Maximum date range is 31 days
// Get advertiser commissions (for advertisers only)
$commissions = $client->commissions()->getAdvertiserCommissions([
'since_date' => '2025-11-01T00:00:00Z',
'before_date' => '2025-11-15T00:00:00Z'
]);
[
'count' => 5,
'records' => [
[
'advertiser_name' => 'BraceAbility',
'posting_date' => '2025-11-10T00:00:00Z',
'pub_commission_amount_usd' => 25.50,
'action_tracker_name' => 'Purchase',
// ... more fields
]
]
]
$terms = $client->programTerms()->search([
'advertiser-ids' => '123456'
]);
$properties = $client->promotionalProperties()->search([
'advertiser-id' => '123456'
]);
$client = new CJClient([
'access_token' => 'your_token',
'publisher_id' => 'your_id',
'cache_enabled' => true,
'cache_ttl' => 3600 // 1 hour
]);
$client = new CJClient([
'access_token' => 'your_token',
'publisher_id' => 'your_id',
'debug' => true
]);
$client = new CJClient([
'access_token' => 'your_token',
'publisher_id' => 'your_id',
'timeout' => 60 // 60 seconds
]);
use CJAffiliate\Exceptions\CJException;
try {
$links = $client->products()->search([
'website_id' => 'your_website_id'
]);
} catch (CJException $e) {
echo "Error: " . $e->getMessage() . "\n";
echo "HTTP Code: " . $e->getCode() . "\n";
// Get additional error details
$response = $e->getResponse();
if ($response) {
print_r($response);
}
}
bash
composer bash
git clone https://github.com/luizsilva-dev/cj-sdk-php.git
cd cj-sdk-php
composer install
bash
git clone https://github.com/luizsilva-dev/cj-sdk-php.git
cd cj-sdk-php
composer install