PHPackages                             imper86/php-allegro-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. imper86/php-allegro-api

ActiveLibrary[API Development](/categories/api)

imper86/php-allegro-api
=======================

PHP SDK for Allegro.pl REST API

v3.2.1(5mo ago)1817.4k↓34.5%16MITPHPPHP &gt;=7.4

Since Mar 13Pushed 5mo ago4 watchersCompare

[ Source](https://github.com/imper86/php-allegro-api)[ Packagist](https://packagist.org/packages/imper86/php-allegro-api)[ RSS](/packages/imper86-php-allegro-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (36)Used By (0)

Allegro.pl REST API PHP SDK
===========================

[](#allegropl-rest-api-php-sdk)

Upgrading v1.x.x -&gt; v2.x.x -&gt; v3.x.x
------------------------------------------

[](#upgrading-v1xx---v2xx---v3xx)

V2 introduced PHP &gt;=7.4 support (8.0 is also supported). All you need to do is change version in `composer.json`file. All resources and methods are the same as in V1, so you don't need to update your code.

V1 will not be maintained anymore, so please upgrade as fast as you can.

Installation
------------

[](#installation)

Just use composer:

```
composer require imper86/php-allegro-api
```

### HTTPlug note

[](#httplug-note)

This lib uses [HTTPlug](https://github.com/php-http/httplug)so it doesn't depend on any http client. In order to use this lib you must have some [PSR-18 http client](https://www.php-fig.org/psr/psr-18)and [PSR-17 http factories](https://www.php-fig.org/psr/psr-17). If you don't know which one you shoud install you can require these:

```
composer require php-http/guzzle6-adapter http-interop/http-factory-guzzle
```

Authentication &amp; usage
--------------------------

[](#authentication--usage)

Library has a bunch of mechanisms that allows you to forget about tokens, expirations etc. But in order to start using it you must authorize user using Oauth flow.

```
use Imper86\PhpAllegroApi\AllegroApi;
use Imper86\PhpAllegroApi\Model\Credentials;
use Imper86\PhpAllegroApi\Oauth\FileTokenRepository;
use Imper86\PhpAllegroApi\Plugin\AuthenticationPlugin;

// first, create Credentials object
$credentials = new Credentials(
    'your-client-id',
    'your-client-secret',
    'your-redirect-uri',
    true //is sandbox
);

// create api client
$api = new AllegroApi($credentials);

// get the authorization URL, and redirect your user:
$state = 'your-random-secret-state';
header(sprintf('Location: %s', $api->oauth()->getAuthorizationUri(true, $state)));

/*
 * after successfull authorization, user will be refirected to your
 * redirect_uri with state and code as query parameters
 */

// verify the state and fetch token
if ($state !== $_GET['state'] ?? null) {
    throw new Exception('CSRF?!');
}

$token = $api->oauth()->fetchTokenWithCode($_GET['code']);

// create TokenRepository object
$tokenRepository = new FileTokenRepository(
    $token->getUserId(),
    __DIR__ . '/tokens'
);
$tokenRepository->save($token);

/*
 * You can invent your own TokenRepository, just implement
 * Imper86\PhpAllegroApi\Oauth\TokenRepositoryInterface
 * You can use your DB, Redis, or anything you want.
 */

// now you can add AuthenticationPlugin, which will take care
// of maintaining your tokens

$api->addPlugin(new AuthenticationPlugin($tokenRepository, $api->oauth()));

// * note: of course you can use your own plugin, or AuthenticationPlugin from HTTPlug library

// from now you can use these methods on AllegroApi object:
$api->account()->(...);
$api->afterSalesServiceConditions()->(...);
$api->bidding()->(...);
$api->billing()->(...);
$api->me()->(...);
$api->offers()->(...);
$api->order()->(...);
$api->payments()->(...);
$api->pointsOfService()->(...);
$api->pricing()->(...);
$api->sale()->(...);
$api->users()->(...);

// fast example:
var_dump($api->sale()->offers()->tags()->get('123456'));
```

If you use IDE with typehinting such as PHPStorm, you'll easily figure it out. If not, please [take a look in Resource directory](src/Resource)

Device Flow
-----------

[](#device-flow)

```
use Imper86\PhpAllegroApi\AllegroApi;
use Imper86\PhpAllegroApi\Model\Credentials;
use Imper86\PhpAllegroApi\Oauth\FileTokenRepository;
use Imper86\PhpAllegroApi\Plugin\AuthenticationPlugin;

// first, create Credentials object
$credentials = new Credentials(
    'your-client-id',
    'your-client-secret',
    'your-redirect-uri',
    true //is sandbox
);

// create api client
$api = new AllegroApi($credentials);

// Create authorization session
$session = $api->oauth()->getDeviceCode();

// Provide device code and/or url to user
echo 'Please visit: ' . $session->getVerificationUriComplete();

// Poll for authorization result
$interval = $session->getInterval();
$token = false;
do {
    sleep($interval);
    $device_code = $session->getDeviceCode();
    try{
        $token = $api->oauth()->fetchTokenWithDeviceCode($device_code);
    } catch (AuthorizationPendingException) {
        continue;
    } catch (SlowDownException) {
        $interval++;
        continue;
    }
} while ($token == false);

// create TokenRepository object
$tokenRepository = new FileTokenRepository(
    $token->getUserId(),
    __DIR__ . '/tokens'
);
$tokenRepository->save($token);
```

Contributing
------------

[](#contributing)

Any help will be very appreciated :)

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance71

Regular maintenance activity

Popularity38

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 79% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Recently: every ~51 days

Total

35

Last Release

162d ago

Major Versions

v1.1.3 → v2.0.02021-05-10

v1.x-dev → v2.0.12021-05-12

v2.4.2 → v3.0.02025-06-23

PHP version history (2 changes)v1.0.1PHP ^7.1

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/aedc51c5ea25d6520027720f9a5599e171e95a47102b66ffd929427f95317561?d=identicon)[imper86](/maintainers/imper86)

---

Top Contributors

[![imper86](https://avatars.githubusercontent.com/u/16724155?v=4)](https://github.com/imper86 "imper86 (49 commits)")[![devEcommercePL](https://avatars.githubusercontent.com/u/155567765?v=4)](https://github.com/devEcommercePL "devEcommercePL (3 commits)")[![mgalejSM](https://avatars.githubusercontent.com/u/74053882?v=4)](https://github.com/mgalejSM "mgalejSM (3 commits)")[![kduma](https://avatars.githubusercontent.com/u/1062582?v=4)](https://github.com/kduma "kduma (2 commits)")[![fzdunek](https://avatars.githubusercontent.com/u/9900496?v=4)](https://github.com/fzdunek "fzdunek (2 commits)")[![Hornir91](https://avatars.githubusercontent.com/u/53277040?v=4)](https://github.com/Hornir91 "Hornir91 (1 commits)")[![dHerc](https://avatars.githubusercontent.com/u/43823377?v=4)](https://github.com/dHerc "dHerc (1 commits)")[![squishfunk](https://avatars.githubusercontent.com/u/23218977?v=4)](https://github.com/squishfunk "squishfunk (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imper86-php-allegro-api/health.svg)

```
[![Health](https://phpackages.com/badges/imper86-php-allegro-api/health.svg)](https://phpackages.com/packages/imper86-php-allegro-api)
```

###  Alternatives

[vonage/client-core

PHP Client for using Vonage's API.

9288.8M18](/packages/vonage-client-core)[joselfonseca/lighthouse-graphql-passport-auth

Add GraphQL types and mutations for login and recover password functionalities

234769.9k1](/packages/joselfonseca-lighthouse-graphql-passport-auth)[imdhemy/appstore-iap

PHP Appstore In-App Purchase implementation

541.5M6](/packages/imdhemy-appstore-iap)[fschmtt/keycloak-rest-api-client-php

PHP client to interact with Keycloak's Admin REST API.

4684.7k2](/packages/fschmtt-keycloak-rest-api-client-php)[oxid-esales/graphql-base

OXID eSales GraphQL base module

24101.0k10](/packages/oxid-esales-graphql-base)[mvdnbrk/dhlparcel-php-api

DHL Parcel API client for PHP

3957.9k5](/packages/mvdnbrk-dhlparcel-php-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
