Skip to content

TrevStoke/Cin7CoreClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cin7 Core API V2 Client for PHP

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages