PHPackages                             retrowaver/allegro-rest-api-v2 - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. retrowaver/allegro-rest-api-v2

ActiveLibrary[HTTP &amp; Networking](/categories/http)

retrowaver/allegro-rest-api-v2
==============================

Second version of a simple interface for Allegro REST API resources. Built on top of https://github.com/Wiatrogon/php-allegro-rest-api, which was rewritten for the most part.

v2.0.0(6y ago)1481MITPHPPHP &gt;=7.2

Since Nov 10Pushed 6y agoCompare

[ Source](https://github.com/retrowaver/php-allegro-rest-api-v2)[ Packagist](https://packagist.org/packages/retrowaver/allegro-rest-api-v2)[ RSS](/packages/retrowaver-allegro-rest-api-v2/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)Dependencies (10)Versions (14)Used By (0)

php-allegro-rest-api-v2
=======================

[](#php-allegro-rest-api-v2)

Second version of a simple interface for Allegro REST API resources. Built on top of , which was rewritten for the most part.

**Main differences are:**

- uses HTTPlug / PSR-7 for HTTP communication
- contains previously missing features (image upload)
- both `authorization code` and `client credentials` flows are supported (`device flow` could be also easily implemented, as authorization is now separated from main API component)
- is flexible (custom headers, custom middleware)

0. Installation
---------------

[](#0-installation)

PHP Allegro REST API uses HTTPlug, and...

> If a library depends on HTTPlug, it requires the virtual package `php-http/client-implementation`. A virtual package is used to declare that the library needs an implementation of the HTTPlug interfaces, but does not care which implementation specifically.

I recommend guzzle6 adapter, so run the following command before installing the PHP Allegro REST API library itself:

```
composer require php-http/guzzle6-adapter php-http/message guzzlehttp/psr7

```

Now you're ready to run:

```
composer require retrowaver/allegro-rest-api-v2

```

Note that you don't need to inject HTTP client and message factory into API client - HTTPlug uses `discovery` to find implementations automatically.

If you want to pass client / message factory explicitly to the API client, you can still do that (see `Api.php` constructor method).

1. Registering your app
-----------------------

[](#1-registering-your-app)

In order to use Allegro REST API, you have to register your application (if you haven't done that already - see ).

2. Authorization
----------------

[](#2-authorization)

First, you need to get an authorization token. There are two different *token managers* provided for different types of authorization flows. Use one of them to get a token.

### 2.1. Authorization code flow

[](#21-authorization-code-flow)

Learn how it works here:

To use it with PHP Allegro REST API, do the following:

```
use Retrowaver\Allegro\REST\Token\TokenManager\AuthorizationCodeTokenManager;
use Retrowaver\Allegro\REST\Token\Credentials;

$tokenManager = new AuthorizationCodeTokenManager;
$tokenManager->getUri(
    new Credentials([
        'clientId' => '...',
        'redirectUri' => '...'
    ])
); // show this URI to your user
```

```
use Retrowaver\Allegro\REST\Token\Credentials;
$token = $tokenManager->getAuthorizationCodeToken(
    new Credentials([
        'clientId' => '...',
        'clientSecret' => '...',
        'redirectUri' => '...'
    ]),
    $code // code from $_GET
);
```

### 2.2. Client credentials flow

[](#22-client-credentials-flow)

Client credentials flow doesn't require a user's permission. It's mostly used for accessing public data (searching offers, getting categories tree). Read more here:

```
use Retrowaver\Allegro\REST\Token\TokenManager\ClientCredentialsTokenManager;
use Retrowaver\Allegro\REST\Token\Credentials;

$tokenManager = new ClientCredentialsTokenManager;
$token = $tokenManager->getClientCredentialsToken(
    new Credentials([
        'clientId' => '...',
        'clientSecret' => '...',
        'redirectUri' => '...'
    ])
);
```

### 2.3. Device flow

[](#23-device-flow)

Device flow isn't supported right now. But you could always write your token manager and use the received token with API as usual. Read more here:

3. Refreshing tokens
--------------------

[](#3-refreshing-tokens)

Authorization code tokens can be refreshed (see ).

```
use Retrowaver\Allegro\REST\Token\TokenManager\AuthorizationCodeTokenManager;
use Retrowaver\Allegro\REST\Token\Credentials;

$tokenManager = new AuthorizationCodeTokenManager;
$tokenManager->refreshToken(
    new Credentials([
        'clientId' => '...',
        'clientSecret' => '...',
        'redirectUri' => '...'
    ]),
    $token
);
```

4. Basic usage
--------------

[](#4-basic-usage)

### 4.1. Initializing

[](#41-initializing)

```
use Retrowaver\Allegro\REST\Api;

$api = new Api;
$api->setToken($token); // token received from token manager
```

### 4.2. GET method

[](#42-get-method)

```
// GET https://api.allegro.pl/offers/listing?phrase=dell
$response = $api->offers->listing->get(['phrase' => 'dell']);
```

### 4.3. POST method

[](#43-post-method)

```
// POST https://api.allegro.pl/sale/offers
$response = $api->sale->offers->post($data);
```

### 4.4. PUT method

[](#44-put-method)

```
// PUT https://api.allegro.pl/sale/offers/12345678
$response = $api->sale->offers(12345678)->put($data);
```

### 4.5. DELETE method

[](#45-delete-method)

```
// DELETE https://api.allegro.pl/sale/offers/12345678
$response = $api->sale->offers(12345678)->delete();
```

### 4.6. Command

[](#46-command)

Some resources in API are only accesible using `command pattern` (read more here ).

```
// PUT https://api.allegro.pl/offers/12345678/change-price-commands/00b8837d-b47e-4f28-9930-29a5cdb10e15
$response = $api->offers(12345678)->{'change-price-commands'}()->put($data);
```

In the example above, UUID is generated automatically. If you want, you can generate it yourself, and pass it as an argument:

```
$response = $api->offers(12345678)->{'change-price-commands'}('some-randomly-generated-uuid')->put($data);
```

5. Headers
----------

[](#5-headers)

You can alter headers being sent with your requests. You can do it on request basis, or once for all subsequent requests.

### 5.1. Why alter headers?

[](#51-why-alter-headers)

You may want to alter headers for several different reasons, mainly:

- if you want messages from API returned in Polish (add `Accept-Language: pl-PL`)
- if you want to access beta methods (read more here )

### 5.2. Send a single request with custom headers

[](#52-send-a-single-request-with-custom-headers)

```
$headers = [
    'Content-Type' => 'application/vnd.allegro.beta.v1+json',
    'Accept' => 'application/vnd.allegro.beta.v1+json'
];

$response = $api->categories->get(null, $headers);
```

### 5.3. Set custom headers for subsequent requests

[](#53-set-custom-headers-for-subsequent-requests)

#### 5.3.1. Replacing headers

[](#531-replacing-headers)

Note that there are some custom headers set by default (`Content-Type: application/vnd.allegro.public.v1+json` and `Accept: application/vnd.allegro.public.v1+json`). If you want to replace them, use `setCustomHeaders()`:

```
$headers = [
    'Content-Type' => 'application/vnd.allegro.beta.v1+json',
    'Accept' => 'application/vnd.allegro.beta.v1+json'
];

$api->setCustomHeaders($headers);
```

#### 5.3.2. Adding headers

[](#532-adding-headers)

If you want to add one or more custom headers, use `addCustomHeaders()`:

```
$headers = [
    'Accept-Language' => 'pl-PL'
];

$api->addCustomHeaders($headers);
```

Note that existing custom headers won't be replaced when using this method.

6. Middleware
-------------

[](#6-middleware)

PHP Allegro REST API has a middleware feature, that allows you to alter requests and responses any way you like.

At this point, there's only one 'real' built-in middleware - `ImageUploadMiddleware` that alters request's URI in case of image upload request (from standard `api.allegro.pl` to image upload-specific `upload.allegro.pl`).

### 6.1. Create your own middleware

[](#61-create-your-own-middleware)

You can create your own middleware by creating a class implementing `Retrowaver\Allegro\REST\Middleware\MiddlewareInterface` and passing it into API constructor:

```
$middleware = [
    new CustomMiddleware,
    new AnotherCustomMiddleware
];

$api = new Api(null, null, $middleware);
```

7. Other stuff
--------------

[](#7-other-stuff)

### 7.1. Sandbox

[](#71-sandbox)

If you want to use API with sandbox environment, use `Sandbox` instead of `Api`, `SandboxAuthorizationCodeTokenManager` instead of `AuthorizationCodeTokenManager` and `SandboxClientCredentialsTokenManager` instead of `ClientCredentialsTokenManager`.

7.2. Tests
----------

[](#72-tests)

### 7.2.1. Unit tests

[](#721-unit-tests)

Run unit tests with `vendor/bin/phpunit tests --color`.

### 7.2.2. Sandbox tests

[](#722-sandbox-tests)

`tests-sandbox` contains tests sending real HTTP requests to sandbox environment. If you want to run those, rename `tests-sandbox/config.php.dist` to `tests-sandbox/config.php`, insert your sandbox credentials, and then run `vendor/bin/phpunit tests-sandbox --color`.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 58.4% 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 ~115 days

Recently: every ~166 days

Total

11

Last Release

2321d ago

Major Versions

0.0.8 → v2.x-dev2019-10-29

PHP version history (2 changes)0.0.1PHP &gt;=5.3

v2.x-devPHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![retrowaver](https://avatars.githubusercontent.com/u/23421260?v=4)](https://github.com/retrowaver "retrowaver (45 commits)")[![Wiatrogon](https://avatars.githubusercontent.com/u/11462938?v=4)](https://github.com/Wiatrogon "Wiatrogon (26 commits)")[![serten-d](https://avatars.githubusercontent.com/u/36070617?v=4)](https://github.com/serten-d "serten-d (3 commits)")[![zbigniewkuras](https://avatars.githubusercontent.com/u/22236689?v=4)](https://github.com/zbigniewkuras "zbigniewkuras (2 commits)")[![marcinc81](https://avatars.githubusercontent.com/u/900272?v=4)](https://github.com/marcinc81 "marcinc81 (1 commits)")

---

Tags

phpapirestallegro

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/retrowaver-allegro-rest-api-v2/health.svg)

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

###  Alternatives

[retailcrm/api-client-php

PHP client for RetailCRM API

68981.8k1](/packages/retailcrm-api-client-php)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[richardfullmer/rabbitmq-management-api

An object oriented wrapper for the RabbitMQ Management HTTP Api

39730.6k8](/packages/richardfullmer-rabbitmq-management-api)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1829.2k2](/packages/huaweicloud-huaweicloud-sdk-php)[brd6/notion-sdk-php

Notion SDK for PHP

5918.0k](/packages/brd6-notion-sdk-php)

PHPackages © 2026

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