trevweb/cin7-core-api-v2-client

A Cin7 Core API V2 Client for PHP

Maintainers

Package info

github.com/TrevStoke/Cin7CoreClient

pkg:composer/trevweb/cin7-core-api-v2-client

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.1 2026-02-23 14:52 UTC

This package is auto-updated.

Last update: 2026-03-23 15:09:56 UTC


README

A PHP client for interacting with the Cin7 Core (formerly DEAR Inventory) API V2.

Installation

composer require trevweb/cin7-core-api-v2-client:^1.0

Usage

Initialise the client

$accountId = 'your_account_id';
$applicationKey = 'your_application_key';
$client = new Cin7CoreApiV2Client($accountId, $applicationKey);

Get a specific product

try {
    $product = $client->get(Cin7CoreEndpoints::PRODUCT, ['Name' => 'Big Tyre']);
    print_r($product);
} catch (Exception $e) {
    // Handle exception
    echo "Error fetching product: " . $e->getMessage();
}

Create a sale

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();
}

Fetch all products (pagination)

try {
    $products = $client->fetchAll(Cin7CoreEndpoints::PRODUCT, 'Products');
    foreach ($products as $product) {
        print_r($product);
    }
} catch (Exception $e) {
    echo "Error fetching products: " . $e->getMessage();
}

Examples

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');

Testing

This package uses PHPUnit for testing. To run the tests, first ensure you have installed the development dependencies:

composer install

Then, run the tests using the following command:

./vendor/bin/phpunit

The tests use a mocked version of the client to avoid making actual API calls.

License

This project is licensed under the MIT License - see the LICENSE file for details.