PHPackages                             mygrainexchange/mgx-php - 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. mygrainexchange/mgx-php

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

mygrainexchange/mgx-php
=======================

Official PHP client for the MGX Enterprise API. Browse anonymized inventory, place bids, read your team's trades and bids, manage cash bids, subscribe to webhooks, and read market prices. Authenticate with OAuth2 (Login with MGX). Seller identity is never exposed until a trade is paid on both sides.

1.0.1(2w ago)01MITPHPPHP ^8.1

Since Jun 19Pushed 2w agoCompare

[ Source](https://github.com/mygrainexchange/mgx-php)[ Packagist](https://packagist.org/packages/mygrainexchange/mgx-php)[ Docs](https://developers.mygrainexchange.com)[ RSS](/packages/mygrainexchange-mgx-php/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (8)Versions (3)Used By (0)

mygrainexchange/mgx-php
=======================

[](#mygrainexchangemgx-php)

Official PHP client for the [MGX Enterprise API](https://developers.mygrainexchange.com).

```
composer require mygrainexchange/mgx-php
```

Requires PHP 8.1+.

Quickstart
----------

[](#quickstart)

```
use MyGrainExchange\Mgx\Overlay\MgxClient;
use MyGrainExchange\Mgx\Overlay\MgxApiError;

$mgx = new MgxClient(
    clientId: getenv('MGX_CLIENT_ID'),
    clientSecret: getenv('MGX_CLIENT_SECRET'),
    scopes: ['inventory.read', 'market.read'],
    // baseUrl: 'https://dashboard.mgx.test/v1', // for local development
);

// Auto-paginates the { items, limit, offset, next } envelope.
foreach ($mgx->inventory()->list(['commodity' => 'wheat', 'minQuantity' => 50]) as $lot) {
    echo $lot->getId(), ' ', $lot->getQuantityMt(), ' ', $lot->getAskingPrice()?->getAmount(), PHP_EOL;
}
```

You can also construct with an options array:

```
$mgx = MgxClient::create([
    'clientId' => getenv('MGX_CLIENT_ID'),
    'clientSecret' => getenv('MGX_CLIENT_SECRET'),
    'scopes' => ['inventory.read', 'market.read'],
]);
```

Authentication
--------------

[](#authentication)

- **Client credentials** (read-only data) — pass `clientId` + `clientSecret` + `scopes`; the SDK acquires, caches, and refreshes the token for you.
- **Login with MGX** (user-context: bids, trades, teams, cash bids, webhooks) — complete the authorization-code + PKCE flow, then pass the resulting `accessToken` (and optionally `refreshToken`) to `MgxClient`.

Features
--------

[](#features)

- **Resource namespaces** — `inventory()`, `market()`, `bids()`, `trades()`, `teams()`, `cashBids()`, `webhooks()`.
- **Auto-pagination** — every `list()` returns a `Paginator` you can `foreach` over; it follows `next` until the result set is exhausted (`->toArray()` collects eagerly).
- **Idempotency** — `inventory()->placeBid()` and `cashBids()->create()` send an `Idempotency-Key` automatically (override with the `$idempotencyKey` argument).
- **Typed errors** — non-2xx responses throw `MgxApiError` with `status()`, `code()`, `getMessage()`, and `fieldErrors()`.

```
try {
    $bid = $mgx->inventory()->placeBid('inv_3Kd9aZ', [
        'quantity_mt' => 50,
        'price' => ['amount' => 312.5],
        'delivery' => ['from' => '2026-08-01', 'to' => '2026-09-30'],
    ]);
} catch (MgxApiError $e) {
    error_log("{$e->status()} {$e->code()} {$e->getMessage()}");
}
```

Generated code
--------------

[](#generated-code)

The `lib/` client is generated from the OpenAPI spec; the ergonomic layer lives in `overlay/` (namespace `MyGrainExchange\Mgx\Overlay`). Do not hand-edit `lib/` — change the API spec and regenerate. See the [mgx-sdks](https://github.com/mygrainexchange/mgx-sdks) repo.

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance96

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~26 days

Total

2

Last Release

18d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/294968511?v=4)[My Grain Exchange](/maintainers/mygrainexchange)[@mygrainexchange](https://github.com/mygrainexchange)

---

Top Contributors

[![mygrainexchange](https://avatars.githubusercontent.com/u/294968511?v=4)](https://github.com/mygrainexchange "mygrainexchange (3 commits)")

---

Tags

apisdkrestoauth2mgxgrainmygrainexchange

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mygrainexchange-mgx-php/health.svg)

```
[![Health](https://phpackages.com/badges/mygrainexchange-mgx-php/health.svg)](https://phpackages.com/packages/mygrainexchange-mgx-php)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

293.1k](/packages/eslazarev-wildberries-sdk)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

37234.5k2](/packages/onesignal-onesignal-php-api)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1831.5k2](/packages/huaweicloud-huaweicloud-sdk-php)

PHPackages © 2026

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