dropcart / dropcart-api-php
Dropcart API connector for PHP
Requires
- php: ^7.4 | ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.5 || ^7.3
- lcobucci/jwt: ^4.3
- nesbot/carbon: ^2.27
Requires (Dev)
- fakerphp/faker: ^1.9
- mockery/mockery: ^1.3
- phpcompatibility/php-compatibility: *
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: *
- vlucas/phpdotenv: ^4.1
README
Introduction
Dropcart is an e-commerce platform for drop shipping. With this API connector, you can use your own solutions (like a web shop or supply management system) to interact with the Dropcart platform.
Requirements
To use the Dropcart API connector, all you need are the public and private key. These can be found in the settings of each supplier or shop you have created in your account on the Dropcart website.
The Dropcart API connector requires PHP 7.2 at minimum. You may need to install and enable the JSON module.
Installation
The easiest way to install the Dropcart API connector is through Composer.
$ composer require dropcart/dropcart-api-php
Getting started
Initialize the Dropcart API connector:
$token = (new \Dropcart\Api\Token())->setKeyPairFromEnvironment();
$dropcart = new \Dropcart\Api\Client($token);
The first line reads the public and private key (the key pair) from the
environment, which is the recommended way. By default the environment variables are
called DROPCART_PUBLIC_KEY
and DROPCART_PRIVATE_KEY
, but you can use others. See
the documentation for more details and another way to set the key pair.
Example
Retrieve a paginated list of products:
$products = $dropcart->supplier()->products()->list(new \Dropcart\Api\Types\Supplier\Product\Listing());
This will give you an ProductCollection
instance. You can get the data through the
getData()
method or simply iterate over the object with foreach
:
// returns array of ProductResource objects
$products->getData();
foreach ($products as $product) {
// $product is a ProductResource
}
The Listing
parameter instance contains methods to control what data you want to see
returned.