PHP code example of aqtivite / php

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

    

aqtivite / php example snippets


use Aqtivite\Php\Aqtivite;

$client = new Aqtivite('client-id', 'client-secret');

$response = $client->user()->events()->get();

$client = new Aqtivite('client-id', 'client-secret');
$client->testMode(); // api.test.aqtivite.com.tr adresine bağlanır

$client->setBaseUrl('https://custom-api.example.com');

use Aqtivite\Php\Contracts\HttpTransportInterface;
use Aqtivite\Php\Http\TransportResponse;

class LaravelTransport implements HttpTransportInterface
{
    public function send(string $method, string $url, array $options = []): TransportResponse
    {
        $response = Http::withHeaders($options['headers'] ?? [])
            ->send($method, $url, $options);

        return new TransportResponse(
            statusCode: $response->status(),
            body: $response->json() ?? [],
            headers: array_map(fn (array $values) => implode(', ', $values), $response->headers()),
        );
    }
}

$client = new Aqtivite('client-id', 'client-secret');
$client->setTransport(new LaravelTransport());

$client = new Aqtivite('client-id', 'client-secret', ['admin:venues:read']);

$client->setScopes(['admin:tickets:read']);

$token = $client->issueToken();

$client->setToken('access-token', new DateTimeImmutable('2026-10-05 12:00:00'));

$token = $client->getToken();
$token->accessToken;
$token->expiresAt;   // DateTimeImmutable|null
$token->tokenType;
$token->scopes;       // API'nin token cevabında bildirdiği scope'lar
$token->isExpired();

$client->onTokenIssued(function (Token $token) {
    Cache::put('aqtivite_token', [
        'access_token' => $token->accessToken,
        'expires_at' => $token->expiresAt?->format(DATE_ATOM),
    ]);
});

// Kullanıcılar
$client->user()->users()->get();                                          // Listele
$client->user()->users()->get(filter: ['name' => 'mehmet']);              // Filtrele
$client->user()->users()->get(query: ['page' => 2, 'length' => 20]);    // Sayfalama
$client->user()->users()->find('mehmet.ogmen');                           // Detay
$client->user()->users()->events('mehmet.ogmen');                         // Kullanıcının etkinlikleri

// Etkinlikler
$client->user()->events()->get();                                         // Listele
$client->user()->events()->get(query: ['order' => 'price[desc]']);
$client->user()->events()->find('etkinlik-slug');        // Detay

// Etkinlik Kategorileri
$client->user()->eventCategories()->get();
$client->user()->eventCategories()->find(1);

// Seanslar
$client->user()->occurrences()->get(filter: ['event_id' => 6999]);
$client->user()->occurrences()->find(166);

// Organizatörler
$client->user()->organizers()->get();
$client->user()->organizers()->find('aqtivite');

// Mekanlar
$client->user()->venues()->get(filter: ['province_id' => 34]);
$client->user()->venues()->find('mekan-slug');

// İller
$client->user()->provinces()->get();
$client->user()->provinces()->find(34);

// İlçeler
$client->user()->districts()->get(filter: ['province_id' => 3, 'name' => 'ala']);
$client->user()->districts()->get(                      // Filter + sayfalama
    filter: ['province_id' => 3],
    query: ['page' => 1],
);
$client->user()->districts()->find(1);

// Para Birimleri
$client->user()->currencies()->get();

// Arama & Ağ
$client->user()->search('aqtivite');
$client->user()->network();

$response = $client->user()->users()->find('mehmet.ogmen');

$response->successful();       // true
$response->failed();           // false
$response->data;               // Veri (array veya object)
$response->elapsedTime;        // Süre

$response = $client->user()->users()->get();

$response->data;               // Veri listesi
$response->total;              // Toplam kayıt
$response->currentPage;        // Mevcut sayfa
$response->lastPage;           // Son sayfa
$response->from;               // Başlangıç
$response->to;                 // Bitiş
$response->hasNextPage();      // Sonraki sayfa var mı?
$response->hasPreviousPage();  // Önceki sayfa var mı?

use Aqtivite\Php\Exceptions\AuthenticationException;
use Aqtivite\Php\Exceptions\ApiException;
use Aqtivite\Php\Exceptions\AqtiviteException;
use Aqtivite\Php\Exceptions\MissingScopeException;

try {
    $response = $client->user()->users()->get();
} catch (AuthenticationException $e) {
    // Kimlik doğrulama hatası
    echo $e->getMessage();
} catch (MissingScopeException $e) {
    // Yeni token'la da eksik kalan scope'lar
    echo implode(' ', $e->scopes);
} catch (ApiException $e) {
    // API hatası
    echo $e->getMessage();
    echo $e->getCode();       // HTTP hata kodu
    echo $e->errorType;       // Hata tipi (ör: "app")
} catch (AqtiviteException $e) {
    // Genel SDK hatası
    echo $e->getMessage();
}
bash
composer