PHPackages                             metaline/wp-api-client - 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. metaline/wp-api-client

ActiveLibrary[API Development](/categories/api)

metaline/wp-api-client
======================

A PHP client for the WordPress REST API, based on Guzzle.

0.1.0(1w ago)029[7 issues](https://github.com/metaline/wp-api-client/issues)MITPHPPHP ^7.4 || ^8.0CI passing

Since Aug 5Pushed 1w ago2 watchersCompare

[ Source](https://github.com/metaline/wp-api-client)[ Packagist](https://packagist.org/packages/metaline/wp-api-client)[ RSS](/packages/metaline-wp-api-client/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

WP API Client
=============

[](#wp-api-client)

[![Test library](https://github.com/metaline/wp-api-client/actions/workflows/test-library.yml/badge.svg)](https://github.com/metaline/wp-api-client/actions/workflows/test-library.yml/badge.svg)

A PHP client for the WordPress REST API, based on [Guzzle](https://guzzlephp.org/).

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

[](#installation)

The recommended way to install this library is through [Composer](https://getcomposer.org/).

```
composer require metaline/wp-api-client

```

Documentation
-------------

[](#documentation)

### Create the client

[](#create-the-client)

You can create the client instance through the `ClientFactory`. At the moment, only WooCommerce credentials are supported:

```
use MetaLine\WordPressAPIClient\ClientFactory;

$factory = new ClientFactory();
$client = $factory->createFromWooCommerceCredentials(
    $customerKey,
    $customerSecret,
    $apiUrl
);
```

The factory accepts an optional array of options, to customize the timeouts of the requests:

```
$client = $factory->createFromWooCommerceCredentials(
    $customerKey,
    $customerSecret,
    $apiUrl,
    [
        'timeout'         => 60,
        'connect_timeout' => 5,
    ]
);
```

OptionDefaultDescription`timeout``120`Maximum number of seconds to wait for the whole request.`connect_timeout``10`Maximum number of seconds to wait while trying to connect.Both options are passed to Guzzle, so you can refer to the [Guzzle documentation](https://docs.guzzlephp.org/en/stable/request-options.html) for more details.

If you need to access to the WordPress REST API through the WooCommerce API credentials, you need this hook in YOUR installation of WordPress:

```
add_filter('woocommerce_rest_is_request_to_rest_api', function ($enabled) {
	if (!$enabled) {
        $rest_prefix = trailingslashit(rest_get_url_prefix());
        $request_uri = esc_url_raw(wp_unslash($_SERVER['REQUEST_URI']));
        $enabled = false !== strpos($request_uri, $rest_prefix . 'wp/');
    }

    return $enabled;
});
```

### Fetch data from REST API

[](#fetch-data-from-rest-api)

Through the client instance you can fetch data from the WordPress REST API. For example:

```
$customers = $client->request('GET', 'wc/v3/customers');
```

Please, refer to the [WordPress](https://developer.wordpress.org/rest-api/reference/) and [WooCommerce](https://woocommerce.github.io/woocommerce-rest-api-docs/) REST API documentation, for all available methods.

### Helper methods

[](#helper-methods)

The client has five helper methods, one for each REST verb: `get()`, `post()`, `put()`, `patch()` and `delete()`.

HTTP verbHelper methodGET`$client->get($uri, $query)`POST`$client->post($uri, $params)`PUT`$client->put($uri, $params)`PATCH`$client->patch($uri, $params)`DELETE`$client->delete($uri, $query)`- `$uri` is the endpoint of the call;
- `$query` is an array of variables to put in query string;
- `$params` is an array of data to put in the body request;

### Upload files

[](#upload-files)

A special case is the [media](https://developer.wordpress.org/rest-api/reference/media/) endpoints, which allow us to upload a file:

```
$data = [
	'file' => new SplFileObject('/path/to/file.zip'),
];

$client->post('wp/v2/media', $data);
```

### Retries

[](#retries)

A request is sent again, up to 5 times in total, when it fails at the transport level — the host cannot be resolved, the connection is refused or the server times out — and when the server answers with `500`, `502`, `503` or `504`. The other server errors, such as `501` and `505`, describe a server that will keep answering the same way, so they are not retried.

Only the methods that are [idempotent by definition](https://www.rfc-editor.org/rfc/rfc9110#section-9.2.2) are retried: `GET`, `HEAD`, `OPTIONS`, `TRACE`, `PUT` and `DELETE`. A `POST` or a `PATCH` is sent once and never repeated, because neither a transport error nor a `500` tells us whether the server has already processed the request: a timeout on `POST wc/v3/orders`, or a fatal error raised by a hook after the order has been saved, may well leave an order behind, and retrying would create a second one.

Retries are sent one after the other, with no delay in between.

License
-------

[](#license)

This project is made available under the MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance98

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 95% 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

Unknown

Total

1

Last Release

12d ago

### Community

Maintainers

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

---

Top Contributors

[![pongho](https://avatars.githubusercontent.com/u/1329964?v=4)](https://github.com/pongho "pongho (19 commits)")[![omoikane](https://avatars.githubusercontent.com/u/145311?v=4)](https://github.com/omoikane "omoikane (1 commits)")

---

Tags

apiapi-clientphprestrest-apiwoocommercewordpress

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/metaline-wp-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/metaline-wp-api-client/health.svg)](https://phpackages.com/packages/metaline-wp-api-client)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.5k](/packages/laravel-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k6.0M777](/packages/sylius-sylius)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.7M7](/packages/avalara-avataxclient)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19467.3M1.9k](/packages/drupal-core)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

762297.9k53](/packages/civicrm-civicrm-core)

PHPackages © 2026

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