1. Go to this page and download the library: Download mygrainexchange/mgx-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mygrainexchange / mgx-php example snippets
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;
}