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.0(today)00MITPHPPHP ^8.1

Since Jun 19Pushed todayCompare

[ 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 today

READMEChangelogDependencies (4)Versions (2)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

39

—

LowBetter than 85% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

0d 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 (1 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.2k532.1M2.5k](/packages/aws-aws-sdk-php)[onesignal/onesignal-php-api

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

34199.5k2](/packages/onesignal-onesignal-php-api)[zenditplatform/zendit-php-sdk

PHP client for Zendit API

1194.4k](/packages/zenditplatform-zendit-php-sdk)[elasticemail/elasticemail-php

The PHP library for the Elastic Email REST API. This API is based on the REST API architecture, allowing the user to easily manage their data with this resource-based approach. To start using this API, you will need your Access Token. Remember to keep it safe.

14107.5k2](/packages/elasticemail-elasticemail-php)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1830.2k2](/packages/huaweicloud-huaweicloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

232.5k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

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