PHP code example of vt-parhomenko / olx-ua-api-sdk
1. Go to this page and download the library: Download vt-parhomenko/olx-ua-api-sdk 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/ */
vt-parhomenko / olx-ua-api-sdk example snippets
use Parhomenko\Olx\OlxFactory;
use Parhomenko\Olx\Country;
$olx = OlxFactory::get(Country::UA, [
'client_id' => 'your-client-id',
'client_secret' => 'your-client-secret',
'access_token' => 'stored-access-token',
'refresh_token' => 'stored-refresh-token',
'token_type' => 'Bearer',
'expires_in' => 86400,
'updated_at' => '2026-05-30T12:00:00+03:00', // ISO-8601 (offset-aware); when issued/stored
], $update_token = true); // auto-refresh the access token if it has expired
// Create an advert
$advert = $olx->adverts()->create([
// ...advert payload, see the OLX API docs
]);
use GuzzleHttp\HandlerStack;
use Parhomenko\Olx\Country;
use Parhomenko\Olx\OlxFactory;
$stack = HandlerStack::create();
$stack->push($myLoggingOrRetryMiddleware); // any Guzzle middleware
$olx = OlxFactory::get(Country::UA, $credentials, false, [
'timeout' => 30, // total seconds per request
'connect_timeout' => 5, // seconds to establish the connection
'handler' => $stack,
]);
$olx->getHttpClient(); // the configured GuzzleHttp\ClientInterface
use Parhomenko\Olx\OlxFactory;
use Parhomenko\Olx\Country;
$olx = OlxFactory::get(Country::UA, [
'client_id' => 'your-client-id',
'client_secret' => 'your-client-secret',
]);
// 1. Redirect the user to the OLX consent screen
$url = $olx->authenticator()->getOAuthLink('https://your-app.test/callback', 'optional-state');
header('Location: ' . $url);
// 2. On your callback, exchange the received ?code for tokens
$auth = $olx->authenticator()->authorize($_GET['code'], 'https://your-app.test/callback');
// 3. Persist the tokens for later use
$tokens = [
'access_token' => $auth->getAccessToken(),
'refresh_token' => $auth->getRefreshToken(),
'token_type' => $auth->getTokenType(),
'expires_in' => $auth->getTokenExpiresIn(),
'updated_at' => $auth->getTokenUpdatedAt(), // ISO-8601, set by the SDK on authorize/refresh
];
// Refresh only when needed (compares updated_at + expires_in to now)
$olx->authenticator()->checkToken();
// Or force a refresh
$olx->authenticator()->refreshToken();
use Parhomenko\Olx\Exceptions\ValidationException;
use Parhomenko\Olx\Exceptions\CallLimitException;
use Parhomenko\Olx\Exceptions\BaseOlxException;
try {
$olx->adverts()->create($payload);
} catch (ValidationException $e) {
$errors = $e->getValidation();
} catch (CallLimitException $e) {
// back off and retry later
} catch (BaseOlxException $e) {
// any other OLX API error
error_log($e->getTitle() . ': ' . $e->getDetail());
}
// 2.x
OlxFactory::get('ua', $credentials);
// 3.0 — positional string calls still work, enum is recommended
OlxFactory::get(Country::UA, $credentials);
OlxFactory::get('ua', $credentials); // still valid
// 2.x
$olx->adverts()->delete_notactive($id); // DELETE only
$olx->adverts()->delete($id); // deactivated, then deleted
// 3.0
$olx->adverts()->delete($id); // single DELETE (replaces delete_notactive)
$olx->adverts()->deactivate($id); // call explicitly if you need the old
$olx->adverts()->delete($id); // deactivate-then-delete behaviour