PHP code example of pushizo / pushizo-php

1. Go to this page and download the library: Download pushizo/pushizo-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/ */

    

pushizo / pushizo-php example snippets


$hs = new \Pushizo\Client([
    'api_key' => getenv('HS_API_KEY'),   // hs_live_…
    'app_id' => getenv('HS_APP_ID'),     // çağrıda app verilmezse kullanılır
    'base_url' => 'https://api.pushizo.com',
    'max_retries' => 3,                  // 429 her metotta; 5xx/ağ hatası GET/PUT/DELETE'te, POST/PATCH'te yalnızca Idempotency-Key varsa veya istek gönderilemediyse
    'timeout' => 30,
    'auto_idempotency_key' => true,      // notifications->create ve users->upsert için otomatik UUID
]);

// Bildirim ve kitle tahmini
$hs->notifications->estimate(['target' => ['erId",
    'target' => ['cations->exportEvents($msg['id']); // CSV işi; tamamlanınca download_url

// Segment ve kampanya yaşam döngüsü
$segment = $hs->segments->create([
    'name' => 'VIP',
    'definition' => ['all' => [['field' => 'tag:plan', 'op' => 'eq', 'value' => 'pro']]],
]);
$hs->segments->estimate($segment['id'], force: true);
$campaign = $hs->campaigns->create(['name' => 'Bahar indirimi', 'audience' => ['segments' => [$segment['id']]]]);
$hs->campaigns->schedule($campaign['id'], ['send_at' => '2026-11-01T09:00:00Z']);
$hs->campaigns->stats($campaign['id']);

// Şablon render önizlemesi ve başka app'e kopyalama
$hs->templates->render('tpl_…', ['channel' => 'email', 'user' => ['external_id' => 'u-1']]);
$hs->templates->copyToApp('tpl_…', ['target_app_id' => 'app_…']);

// Analitik (dizi veya CSV metni)
$report = $hs->analytics->messages(['from' => '2026-10-01T00:00:00Z', 'compare' => true]);
$csv = $hs->analytics->messages(['format' => 'csv']);

// İçe aktarma (multipart)
$hs->imports->createFromFile('csv_users', __DIR__ . '/kullanicilar.csv');

// Kullanıcı kutusu ve token ile abonelik güncelleme
$hs->inbox->readAll('external_id', 'u-1');
$hs->subscriptions->updateByToken('email', '[email protected]', ['status' => 'unsubscribed']);

// API anahtarı: düz anahtar yalnızca bu yanıtta döner, loglamayın
$created = $hs->apiKeys->create(['name' => 'ci', 'scopes' => ['notifications:write']]);

$cmp = $hs->campaigns->create([
    'name' => 'Bahar',
    'variants' => [
        ['name' => 'A', 'weight_percent' => 45, 'content' => ['contents' => ['tr' => 'Bahar indirimi']]],
        ['name' => 'B', 'weight_percent' => 45, 'content' => ['contents' => ['tr' => '%20 indirim']]],
        ['name' => 'Kontrol', 'weight_percent' => 10, 'is_control' => true],
    ],
    'ab_test' => ['enabled' => true, 'test_percentage' => 30, 'winner' => ['mode' => 'auto', 'metric' => 'click_rate', 'evaluate_after_minutes' => 120]],
]);
$stats = $hs->campaigns->variantStats($cmp['id']); // varyant bazlı oranlar + anlamlılık
$hs->campaigns->selectWinner($cmp['id'], $stats['variants'][0]['variant_id']); // elle seçim

// Kategoriler ve kullanıcı tercihleri (kategoriye kapalı kullanıcıya o kategori gönderilmez)
$hs->preferences->createCategory(['key' => 'marketing', 'name' => ['tr' => 'Pazarlama', 'en' => 'Marketing']]);
$hs->preferences->setUser('external_id', 'u-1', [['category' => 'marketing', 'channel' => 'email', 'opted_in' => false]]);
$hs->templates->stats('tpl_1');
$hs->analytics->retention(['weeks' => 8]);

$journey = $hs->journeys->create(['name' => 'Sipariş sonrası']);
$hs->journeys->saveDraft($journey['id'], [
    'graph' => [
        'nodes' => [
            ['id' => 'trg', 'type' => 'trigger', 'position' => ['x' => 0, 'y' => 0], 'data' => ['trigger' => ['kind' => 'api']]],
            ['id' => 'push', 'type' => 'send_push', 'position' => ['x' => 0, 'y' => 120],
             'data' => ['content' => ['contents' => ['tr' => 'Siparişin yolda', 'en' => 'Your order has shipped']]]],
            ['id' => 'end', 'type' => 'exit', 'position' => ['x' => 0, 'y' => 240], 'data' => ['label' => 'Bitiş']],
        ],
        'edges' => [
            ['id' => 'e1', 'source' => 'trg', 'target' => 'push', 'sourceHandle' => 'next'],
            ['id' => 'e2', 'source' => 'push', 'target' => 'end', 'sourceHandle' => 'next'],
        ],
    ],
    'settings' => ['re_entry' => ['mode' => 'after_exit']],
]);
$published = $hs->journeys->publish($journey['id']); // ['journey', 'version', 'issues']

// API tetikleyicisi: kullanıcı external_id, user_id veya alias ile seçilir
$result = $hs->journeys->triggerRun($journey['id'], ['external_id' => 'u-1', 'context' => ['order_id' => 'o-42']]);
if ($result['entered'] && $result['run'] !== null) {
    $run = $hs->journeys->getRun($journey['id'], $result['run']['id']);
}
$stats = $hs->journeys->stats($journey['id'], ['version' => $published['version']]);
foreach ($hs->paginate(fn (?string $c) => $hs->journeys->listRuns($journey['id'], ['status' => 'waiting', 'cursor' => $c])) as $r) {
    echo $r['id'], ' ', $r['current_node_id'], PHP_EOL;
}

// Data feed ve içerik tablosu (şablonda {{ feed.stok.adet }} ve tablo araması)
$feed = $hs->dataFeeds->create(['name' => 'stok', 'url_template' => 'https://example.com/stok/{{ user.external_id }}']);
$hs->dataFeeds->test($feed['id'], ['external_id' => 'u-1']);
$table = $hs->contentTables->createFromFile(['name' => 'urunler', 'key_column' => 'sku'], __DIR__ . '/urunler.csv');
$hs->contentTables->replaceRowsFromFile($table['id'], __DIR__ . '/urunler-yeni.csv'); // sürüm artar

// İki yönlü konuşmalar (WhatsApp 24 saat penceresi dışında yalnızca onaylı şablon)
foreach ($hs->paginate(fn (?string $c) => $hs->conversations->list(['unread' => true, 'cursor' => $c])) as $conv) {
    $hs->conversations->reply($conv['id'], ['text' => 'Teşekkürler, inceliyoruz.']);
    $hs->conversations->markRead($conv['id']);
}

// E-posta adres doğrulama ve ısındırma planı
$hs->emailDeliverability->verifyAddress('[email protected]');
$hs->emailDeliverability->createWarmupPlan(['name' => 'Yeni alan adı', 'kind' => 'domain', 'target' => 'mail.example.com']);

// Veri ambarı dışa aktarımı: kimlik bilgisi şifreli saklanır, yanıtta dönmez
$export = $hs->warehouseExports->create([
    'name' => 'BigQuery', 'tables' => ['events', 'deliveries'], 'destination' => 'bigquery',
    'config' => ['project_id' => 'proje-1', 'dataset' => 'pushizo'],
    'credentials' => ['service_account_json' => getenv('GCP_SA_JSON')],
]);
$hs->warehouseExports->run($export['id']);

// Ekip gelen kutusu: durum, atama, etiket ve metrikler
$hs->conversations->assign('cnv_1', ['team_id' => 'team_1', 'assignee_id' => null]);
$hs->conversations->updateTags('cnv_1', ['add' => ['plan' => 'pro'], 'remove' => ['lead']]);
$hs->conversations->update('cnv_1', ['status' => 'resolved']);
$metrics = $hs->inbox->metrics(['from' => '2026-10-01T00:00:00Z', 'channel' => 'chat']);
$hs->inbox->createCannedResponse(['shortcut' => 'iade', 'title' => 'İade', 'body' => 'Merhaba {{ contact.name }}, iadeniz alındı.']);

// Reklam raporlama ve bütçe uyarıları; from/to zorunlu
$spend = $hs->ads->spendReport(['from' => '2026-10-01', 'to' => '2026-10-31', 'group_by' => 'campaign']);
$hs->ads->updateCampaign('ade_1', ['status' => 'paused']); // platforma da yazılır
$hs->ads->createAlertRule(['name' => 'Günlük tavan', 'kind' => 'daily_spend', 'threshold' => 500, 'recipients' => ['[email protected]']]);

// Web büyüme: kampanya taslak oluşur, setStatus ile yayınlanır
$popup = $hs->webCampaigns->create([
    'name' => 'Bülten pop-up',
    'display' => ['layout' => 'popup', 'blocks' => [['type' => 'title', 'text' => ['tr' => 'Bültenimize katılın']]], 'form_id' => 'frm_1'],
    'trigger' => ['kind' => 'exit_intent'],
]);
$hs->webCampaigns->setStatus($popup['id'], 'active');
$hs->forms->submit('frm_1', ['values' => ['email' => '[email protected]'], 'external_id' => 'u-1']); // sunucu tarafı gönderim
foreach ($hs->paginate(fn (?string $c) => $hs->forms->listSubmissions('frm_1', ['status' => 'confirmed', 'cursor' => $c])) as $s) {
    echo $s['id'], PHP_EOL;
}
$nps = $hs->surveys->report('srv_1', ['days' => 30]);
$hs->landingPages->publish('lp_1');
bash
composer config repositories.pushizo vcs https://github.com/pushizo/pushizo-php
composer 
bash
composer 
bash
composer 
bash
composer config repositories.pushizo vcs https://github.com/pushizo/pushizo-php
composer 
bash
php tests/run.php                                              # bağımlılıksız test koşucusu
for f in src/*.php src/*/*.php tests/*.php; do php -l "$f"; done