dominicwatts / onbuysdk
OnBuy PHP SDK
Installs: 601
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 3
Open Issues: 0
Type:project
Requires
- php: >=7.1.3
- laminas/laminas-http: 2.12.0
- laminas/laminas-json: ^3.1
Requires (Dev)
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: 9.3.7
- symfony/var-dumper: v4.4.11
README
OnBuy - UK Online Marketplace & Amazon Alternative
Unofficial PHP SDK to interact with OnBuy API
Install Instructions
composer require dominicwatts/onbuysdk
There is a composer archive at:
https://packagist.org/packages/dominicwatts/onbuysdk
API Documentation
https://docs.api.onbuy.com/?version=latest
Connection Details
The API settings page can be found in your Seller Control Panel. There are two sets of keys, Live and Test. You should use the Test keys when integrating with the API and switch to the Live Keys when you are ready to go live.
https://seller.onbuy.com/inventory/integrations/onbuy-api/
Usage
Get token
To connect to any API method, you first need to obtain your temporary secret access token.
require 'vendor/autoload.php'; $config = [ 'consumer_key' => 'test_consumer_key', 'secret_key' => 'test_secret_key' ]; use Xigen\Library\OnBuy\Auth; $auth = new Auth( $config ); $auth->getToken(); // This is your token
The access token is only valid for 15 minutes, after which a new token will need to be requested.
To debug
$auth->getResponse()->getBody();
$auth->getResponseArray();
$auth->getExpires();
General process
- Load token
- Build request
- Perform request and return results
Brands
use Xigen\Library\OnBuy\Brand\Brand; $brand = new Brand($auth->getToken()); $brand->getBrand('keyword', 'asc', 10, 0); $brand->getResponse(); $brand->getBrandById(123); $brand->getResponse();
Categories
Categories
use Xigen\Library\OnBuy\Category\Category; $category = new Category($auth->getToken()); $category->getCategory([ 'name' => 'test' ]); $category->getResponse(); $category->getCategory([ 'name' => 'test', 'category_type_id' => 1 // department ]); $category->getResponse(); $category->getCategoryById(13490); $category->getResponse();
Categories Features
use Xigen\Library\OnBuy\Category\Feature; $categoryFeature = new Feature($auth->getToken()); $categoryFeature->getFeatureById(13490); $categoryFeature->getResponse();
Categories Technical Details
use Xigen\Library\OnBuy\Category\Technical; $categoryTechnical = new Technical($auth->getToken()); $categoryTechnical->getTechnicalDetailById(13490); $categoryTechnical->getResponse(); $categoryTechnical->getGroupById(13490, 125); $categoryTechnical->getResponse();
Categories Variants
use Xigen\Library\OnBuy\Category\Variant; $categoryVariant = new Variant($auth->getToken()); $categoryVariant->getVariantId(13490); $categoryVariant->getResponse();
Commission
use Xigen\Library\OnBuy\Commission\Commission; $commission = new Commission($auth->getToken()); $commission->getTier(); $commission->getResponse(); $commission->getTierById(13490, 125); $commission->getResponse();
Condition
use Xigen\Library\OnBuy\Condition\Condition; $condition = new Condition($auth->getToken()); $condition->getCondition(); $condition->getResponse();
Order
use Xigen\Library\OnBuy\Order\Order; $order = new Order($auth->getToken()); $order->getOrder( [ 'status' => 'awaiting_dispatch', 'previously_exported' => 0 ], [ 'created' => 'asc' ] ); $order->getResponse(); $order->getOrderById('T9R7V'); $order->getResponse(); $order->dispatchOrder([['order_id' => 'T9R7V']]); $order->getResponse(); $order->dispatchOrder([ [ "order_id" => "T9R7V", "products" => [ "sku" => "EXP-143-33S", "opc" => "PN8JV6", "quantity" => 125 ], "tracking" => [ "tracking_id" => "bar", "supplier_name" => "bar", "number" => "bar", "url" => "https://example.com/path-to-resource/" ] ] ]); $order->getResponse(); $order->cancelOrder([ 'order_id' => 'T9R7V', 'order_cancellation_reason_id' => 1, 'cancel_order_additional_info' => 'Out of stock' ]); $order->getResponse(); $order->refundOrder([ 'order_id' => 'T9R7V', 'order_refund_reason_id' => 1, 'seller_note' => 'Customer Return', 'customer_note' => 'Item return received - Thank you!' ]); $order->getResponse(); $order->getTrackingProviders(); $order->getResponse();
Product
Product
use Xigen\Library\OnBuy\Product\Product; $product = new Product($auth->getToken()); $product->createProduct($insertArray); $product->getResponse(); $product->testCreateProductByBatch($insertArray); $product->getResponse(); $product->updateProduct($updateArray); // single array $product->getResponse(); $product->updateProductByBatch($updateArray); // array of array $product->getResponse(); $product->getProduct([ 'query' => 'test', 'field' => 'name' ]); $product->getResponse();
Product Listing
use Xigen\Library\OnBuy\Product\Listing; $listing = new Listing($auth->getToken()); $listing->getListing( ['last_created' => 'asc'], ['sku' => 'test'] ); $listing->getResponse(); $listing->updateListingBySku([ [ "sku" => "EXP-143-33S", "price" => 126.34, "stock" => 125, "boost_marketing_commission" => 14.83 ], [ "sku" => "EXP-143-33L", "price" => 126.34, "stock" => 125, "boost_marketing_commission" => 14.83 ], ]); $listing->getResponse(); $listing->deleteListingBySku([ "EXP-143-33S", "EXP-144-33L" ]); $listing->getResponse(); $listing->createListing( 'P5ZVSFF', [[ "sku" => "EXP-143-33S", "group_sku" => "bar", "boost_marketing_commission" => 2.98 ]] ); $listing->getResponse(); $listing->createListingByBatch( [[ "opc" => "PN8JV6", "condition" => "poor", "price" => 9.99, "stock" => 8, "delivery_weight" => 16, "handling_time" => 125, "free_returns" => "true", "warranty" => 7 ]] ); $listing->getResponse(); $listing->getWinningListing([ "EXP-143-33S", "EXP-144-33L" ]); $listing->getResponse();
Queue
use Xigen\Library\OnBuy\Queue\Queue; $queue = new Queue($auth->getToken()); $queue->getQueue([ 'queue_ids' => '123,456', 'status' => 'pending' ]); $queue->getResponse(); $queue->getQueueById(123); $queue->getResponse();
Seller
Seller
use Xigen\Library\OnBuy\Seller\Seller; $seller = new Seller($auth->getToken()); $seller->getSellerById(123); $seller->getResponse();
Seller Deliveries
use Xigen\Library\OnBuy\Seller\Delivery; $sellerDelivery = new Delivery($auth->getToken()); $sellerDelivery->getDelivery(); $sellerDelivery->getResponse();
Seller Entities
use Xigen\Library\OnBuy\Seller\Entity; $sellerEntity = new Entity($auth->getToken()); $sellerEntity->getEntity(); $sellerEntity->getResponse(); $sellerEntity->getEntityById(123); $sellerEntity->getResponse();
Sites
use Xigen\Library\OnBuy\Site\Site; $site = new Site($auth->getToken()); $site->getSite([ 'name' => 'test' ]); $site->getResponse(); $site->getSiteById(123); $site->getResponse();