PHP code example of ready2order / r2o-api-client-php
1. Go to this page and download the library: Download ready2order/r2o-api-client-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/ */
ready2order / r2o-api-client-php example snippets
use ready2order\Client;
$client = new Client('your-account-token');
// Fetch account information
$company = $client->get('company');
print_r($company);
$client = new Client('your-token');
$client->setTimeout(30); // 30 seconds
// Or override per request (last parameter)
$result = $client->get('products', [], 60); // 60 second timeout
$client = new Client('your-token');
$client->setLanguage('de-DE'); // German
$client->setLanguage('en-US'); // English (default)
$client = new Client('your-token', 'https://custom-api.example.com/v1');
use ready2order\Client;
use ready2order\Exceptions\ErrorResponseException;
use ready2order\Exceptions\ResourceNotFoundException;
use ready2order\Exceptions\InvalidResponseException;
$client = new Client('your-token');
try {
$product = $client->get('products/999999');
} catch (ResourceNotFoundException $e) {
// HTTP 404 - Resource not found
echo "Product not found: " . $e->getMessage();
} catch (ErrorResponseException $e) {
// API returned an error (4xx/5xx)
echo "API error: " . $e->getMessage();
// Access full error response data
$errorData = $e->getData();
if ($errorData) {
print_r($errorData);
}
} catch (InvalidResponseException $e) {
// Response could not be JSON-decoded
echo "Invalid response from API";
}
$client = new Client('your-token');
// Fetch first page of products (default limit varies by endpoint)
$page1 = $client->get('products', [
'page' => 1,
'limit' => 50,
]);
// Fetch next page
$page2 = $client->get('products', [
'page' => 2,
'limit' => 50,
]);
use ready2order\Client;
use ready2order\Exceptions\ErrorResponseException;
$client = new Client('your-token');
// Create a product group
$productGroup = $client->put('productgroups', [
'productgroup_name' => 'Soft drinks',
]);
// Create a product in that group
$product = $client->put('products', [
'product_name' => 'Cola',
'product_price' => '2.50',
'product_vat' => '20',
'productgroup' => [
'productgroup_id' => $productGroup['productgroup_id'],
],
]);
echo "Created product: " . $product['product_name'];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.