2017 © Pedro PelĂĄez
 

library bigcommerce-api

Enables PHP applications to communicate with the Bigcommerce API.

image

jivochat/bigcommerce-api

Enables PHP applications to communicate with the Bigcommerce API.

  • Monday, May 28, 2018
  • by yurka44
  • Repository
  • 1 Watchers
  • 0 Stars
  • 460 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 131 Forks
  • 0 Open issues
  • 32 Versions
  • 5011 % Grown

The README.md

Bigcommerce API Client

PHP client for connecting to the Bigcommerce V2 REST API., (*1)

To find out more, visit the official documentation website: http://developer.bigcommerce.com/, (*2)

Build Status Coverage Status Dependency Status, (*3)

Latest Stable Version Total Downloads, (*4)

Requirements

  • PHP 5.3 or greater
  • cUrl extension enabled

To connect to the API with basic auth you need the following:, (*5)

  • Secure URL pointing to a Bigcommerce store
  • Username of an authorized admin user of the store
  • API key for the user

To generate an API key, go to Control Panel > Users > Edit User and make sure the 'Enable the XML API?' is ticked., (*6)

To connect to the API with OAuth you will need the following:, (*7)

  • client_id
  • auth_token
  • store_hash

Installation

Use the following Composer command to install the API client from the Bigcommerce vendor on Packagist:, (*8)

 $ composer require bigcommerce/api
 $ composer update

You can also install composer for your specific project by running the following in the library folder., (*9)

 $ curl -sS https://getcomposer.org/installer | php
 $ php composer.phar install
 $ composer install

Namespace

All the examples below assume the Bigcommerce\Api\Client class is imported into the scope with the following namespace declaration:, (*10)

use Bigcommerce\Api\Client as Bigcommerce;

Configuration

To use the API client in your PHP code, ensure that you can access Bigcommerce\Api in your autoload path (using Composer’s vendor/autoload.php hook is recommended)., (*11)

Provide your credentials to the static configuration hook to prepare the API client for connecting to a store on the Bigcommerce platform:, (*12)

Basic Auth

Bigcommerce::configure(array(
    'store_url' => 'https://store.mybigcommerce.com',
    'username'  => 'admin',
    'api_key'   => 'd81aada4xc34xx3e18f0xxxx7f36ca'
));

OAuth

In order to obtain the auth_token you would consume Bigcommerce::getAuthToken method, (*13)


$object = new \stdClass(); $object->client_id = 'xxxxxx'; $object->client_secret = 'xxxxx; $object->redirect_uri = 'https://app.com/redirect'; $object->code = $request->get('code'); $object->context = $request->get('context'); $object->scope = $request->get('scope'); $authTokenResponse = Bigcommerce::getAuthToken($object); Bigcommerce::configure(array( 'client_id' => 'xxxxxxxx', 'auth_token' => $authTokenResponse->access_token, 'store_hash' => 'xxxxxxx' ));

Connecting to the store

To test that your configuration was correct and you can successfully connect to the store, ping the getTime method which will return a DateTime object representing the current timestamp of the store if successful or false if unsuccessful:, (*14)

$ping = Bigcommerce::getTime();

if ($ping) echo $ping->format('H:i:s');

Accessing collections and resources (GET)

To list all the resources in a collection:, (*15)

$products = Bigcommerce::getProducts();

foreach ($products as $product) {
    echo $product->name;
    echo $product->price;
}

To access a single resource and its connected sub-resources:, (*16)

$product = Bigcommerce::getProduct(11);

echo $product->name;
echo $product->price;

To view the total count of resources in a collection:, (*17)

$count = Bigcommerce::getProductsCount();

echo $count;

Paging and Filtering

All the default collection methods support paging, by passing the page number to the method as an integer:, (*18)

$products = Bigcommerce::getProducts(3);

If you require more specific numbering and paging, you can explicitly specify a limit parameter:, (*19)

$filter = array("page" => 3, "limit" => 30);

$products = Bigcommerce::getProducts($filter);

To filter a collection, you can also pass parameters to filter by as key-value pairs:, (*20)

$filter = array("is_featured" => true);

$featured = Bigcommerce::getProducts($filter);

See the API documentation for each resource for a list of supported filter parameters., (*21)

Updating existing resources (PUT)

To update a single resource:, (*22)

$product = Bigcommerce::getProduct(11);

$product->name = "MacBook Air";
$product->price = 99.95;
$product->update();

You can also update a resource by passing an array or stdClass object of fields you want to change to the global update method:, (*23)

$fields = array(
    "name"  => "MacBook Air",
    "price" => 999.95
);

Bigcommerce::updateProduct(11, $fields);

Creating new resources (POST)

Some resources support creation of new items by posting to the collection. This can be done by passing an array or stdClass object representing the new resource to the global create method:, (*24)

$fields = array(
    "name" => "Apple"
);

Bigcommerce::createBrand($fields);

You can also create a resource by making a new instance of the resource class and calling the create method once you have set the fields you want to save:, (*25)

$brand = new Bigcommerce\Api\Resources\Brand();

$brand->name = "Apple";
$brand->create();

Deleting resources and collections (DELETE)

To delete a single resource you can call the delete method on the resource object:, (*26)

$category = Bigcommerce::getCategory(22);
$category->delete();

You can also delete resources by calling the global wrapper method:, (*27)

Bigcommerce::deleteCategory(22);

Some resources support deletion of the entire collection. You can use the deleteAll methods to do this:, (*28)

Bigcommerce::deleteAllOptionSets();

Using The XML API

By default, the API client handles requests and responses by converting between JSON strings and their PHP object representations. If you need to work with XML you can switch the API into XML mode with the useXml method:, (*29)

Bigcommerce::useXml();

This will configure the API client to use XML for all subsequent requests. Note that the client does not convert XML to PHP objects. In XML mode, all object parameters to API create and update methods must be passed as strings containing valid XML, and all responses from collection and resource methods (including the ping, and count methods) will return XML strings instead of PHP objects. An example transaction using XML would look like:, (*30)

Bigcommerce::useXml();

$xml = "
        <brand>
            <name>Apple</name>
            <search_keywords>computers laptops</search_keywords>
        </brand>";

$result = Bigcommerce::createBrand($xml);

Handling Errors And Timeouts

For whatever reason, the HTTP requests at the heart of the API may not always succeed., (*31)

Every method will return false if an error occurred, and you should always check for this before acting on the results of the method call., (*32)

In some cases, you may also need to check the reason why the request failed. This would most often be when you tried to save some data that did not validate correctly., (*33)

$orders = Bigcommerce::getOrders();

if (!$orders) {
    $error = Bigcommerce::getLastError();
    echo $error->code;
    echo $error->message;
}

Returning false on errors, and using error objects to provide context is good for writing quick scripts but is not the most robust solution for larger and more long-term applications., (*34)

An alternative approach to error handling is to configure the API client to throw exceptions when errors occur. Bear in mind, that if you do this, you will need to catch and handle the exception in code yourself. The exception throwing behavior of the client is controlled using the failOnError method:, (*35)

Bigcommerce::failOnError();

try {
    $orders = Bigcommerce::getOrders();

} catch(Bigcommerce\Api\Error $error) {
    echo $error->getCode();
    echo $error->getMessage();
}

The exceptions thrown are subclasses of Error, representing client errors and server errors. The API documentation for response codes contains a list of all the possible error conditions the client may encounter., (*36)

Verifying SSL certificates

By default, the client will attempt to verify the SSL certificate used by the Bigcommerce store. In cases where this is undesirable, or where an unsigned certificate is being used, you can turn off this behavior using the verifyPeer switch, which will disable certificate checking on all subsequent requests:, (*37)

Bigcommerce::verifyPeer(false);

Connecting through a proxy server

In cases where you need to connect to the API through a proxy server, you may need to configure the client to recognize this. Provide the URL of the proxy server and (optionally) a port to the useProxy method:, (*38)

Bigcommerce::useProxy("http://proxy.example.com", 81);

The Versions

28/05 2018

dev-master

9999999-dev http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest http ecommerce business

28/05 2018

3.0.9

3.0.9.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest http ecommerce business

23/03 2018

3.0.8

3.0.8.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest http ecommerce business

16/11 2017

3.0.7

3.0.7.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest http ecommerce business

22/07 2016

3.0.6

3.0.6.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

 

The Development Requires

api rest http ecommerce business

15/06 2016

3.0.5

3.0.5.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

09/06 2016

3.0.4

3.0.4.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

29/04 2016

3.0.3

3.0.3.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

29/01 2016

3.0.2

3.0.2.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

27/01 2016

3.0.1

3.0.1.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

20/06 2015

3.0.0

3.0.0.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

20/06 2015

3.0.0-beta.12

3.0.0.0-beta12 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

19/06 2015

3.0.0-beta.11

3.0.0.0-beta11 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

07/05 2015

3.0.0-beta.10

3.0.0.0-beta10 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

21/03 2015

3.0.0-beta.9

3.0.0.0-beta9 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

09/03 2015

3.0.0-beta.8

3.0.0.0-beta8 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

05/03 2015

3.0.0-beta.7

3.0.0.0-beta7 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

04/03 2015

3.0.0-beta.6

3.0.0.0-beta6 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

03/03 2015

3.0.0-beta.5

3.0.0.0-beta5 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

26/02 2015

3.0.0-beta.4

3.0.0.0-beta4 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

26/02 2015

3.0.0-beta.3

3.0.0.0-beta3 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

24/02 2015

3.0.0-beta.2

3.0.0.0-beta2 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

23/02 2015

3.0.0-beta.1

3.0.0.0-beta1 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

07/06 2014

3.x-dev

3.9999999.9999999.9999999-dev http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce v3 API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

12/11 2013

2.0.7

2.0.7.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

14/08 2013

2.0.6

2.0.6.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

20/06 2013

2.0.5

2.0.5.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

02/04 2013

2.0.4

2.0.4.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

05/03 2013

2.0.3

2.0.3.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

26/02 2013

2.0.2

2.0.2.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

api rest http ecommerce business

14/02 2013

2.0.1

2.0.1.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

api rest http ecommerce business

09/02 2013

2.0.0

2.0.0.0 http://developer.bigcommerce.com

Enables PHP applications to communicate with the Bigcommerce API.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

api rest http ecommerce business