SDKs & code examples
Start with the PHP client, or use the Python examples alongside each live endpoint. Both follow the same v1 API contract.
PHP SDK 0.1.0 preview
PHP 8.1+ · cURL · three read endpoints
Install the source package
Download and unzip the package, then run Composer inside the extracted directory to generate its autoloader.
cd cru-php-sdk composer install
This preview is supplied as source. It is not published on Packagist.
Set your environment variables
export CRU_BASE_URL='https://us.cruworldwine.com/api/v1' export CRU_CLIENT_KEY='YOUR_CLIENT_KEY' export CRU_CLIENT_SECRET='YOUR_CLIENT_SECRET'
Use the API hostname Cru supplies for your environment. Keep the credentials in server environment variables or your application’s secret manager.
Make your first request
<?php require 'vendor/autoload.php'; use Cru\Trading\Client; $client = new Client( baseUrl: getenv('CRU_BASE_URL'), clientKey: getenv('CRU_CLIENT_KEY'), clientSecret: getenv('CRU_CLIENT_SECRET'), ); $identity = $client->ping(); print_r($identity['data']);
Available methods
ping() | Confirm your credentials and scopes. |
listMarketBids($params) | Read one page of wine markets. |
getMarketBid($code) | Retrieve one bid by its opaque code. |
iterateMarketBids($params) | Iterate all pages, yielding wine markets. |
Read every page
foreach ($client->iterateMarketBids(['depth' => 'best']) as $market) { echo $market['wine_name'] . PHP_EOL; }
Handle API errors
try { $response = $client->listMarketBids(); } catch (\Cru\Trading\ApiException $e) { // Log metadata only. Never log your secret. error_log(sprintf('%d %s %s', $e->httpStatus, $e->apiCode, $e->requestId)); }
Prefer Python?
Python examples use the requests library. Install it, set your credentials, then choose Python in an endpoint’s request panel.
python -m pip install requestsThe client implements the supplied reference, including TLS verification, timeouts, encoded bid IDs, pagination, and structured errors. It has not been tested against a running Cru API. Planned endpoints are excluded.