A PHP client for interacting with the Cin7 Core (formerly DEAR Inventory) API V2.
composer require trevweb/cin7-core-api-v2-client:^1.0$accountId = 'your_account_id';
$applicationKey = 'your_application_key';
$client = new Cin7CoreApiV2Client($accountId, $applicationKey);try {
$product = $client->get(Cin7CoreEndpoints::PRODUCT, ['Name' => 'Big Tyre']);
print_r($product);
} catch (Exception $e) {
// Handle exception
echo "Error fetching product: " . $e->getMessage();
}try {
$saleData = [
"CustomerID" => "guid-of-customer",
"TaxRule" => "Tax on Sales",
"Location" => "Main Warehouse",
// ... other required fields
];
$response = $client->post('sale', $saleData);
echo "Created Sale ID: " . $response['ID'];
} catch (Exception $e) {
echo "Error creating sale: " . $e->getMessage();
}try {
$products = $client->fetchAll(Cin7CoreEndpoints::PRODUCT, 'Products');
foreach ($products as $product) {
print_r($product);
}
} catch (Exception $e) {
echo "Error fetching products: " . $e->getMessage();
}See the examples directory for more usage examples. Place a file in the examples directory named 'cin7-example-api-credentials.php' with the following contents:
<?php
DEFINE('CIN7_ACCOUNT_ID', 'your-id-here');
DEFINE('CIN7_APPLICATION_KEY', 'your-key-here');This package uses PHPUnit for testing. To run the tests, first ensure you have installed the development dependencies:
composer installThen, run the tests using the following command:
./vendor/bin/phpunitThe tests use a mocked version of the client to avoid making actual API calls.
This project is licensed under the MIT License - see the LICENSE file for details.