Skip to content
skuio edited this page Feb 1, 2020 · 3 revisions

SKU.io SDK

A PHP package to connect to sku.io User API.

Table of contents

Installation

Installation using composer:

composer require skuio/sku-sdk

Usage

  • You need to create or get user API credentials from these APIs User API

    This APIs return

    {
      "key": "f6a9f775f414ecc550a....",
      "secret": "0a9be418866a453cb9...."
    }
  • Use this credentials to connect with sku.io user api (username, password).

  • Set the SDK configurations:

    • username
    • password
    • environment

    you can set url or dev_url if you want to change your testing domains.

  • the SDK handle response automatically and your code get the results using these functions:

    • getStatusCode(): returns http response status of i.e (200,500 ..).
    • getResponse(): returns the JSON format response (response also return errors like validation errors ..etc).
    • getMessage(): returns response message.
    • getData(): returns the data object inside the response.
    • getWarnings(): returns array of warnings if the status_code is 299.
    • getErrors(): returns array of errors if the status_code is not success.
    • getCurlError(): returns the curl error.

Example Usage

Here is an example of a function used to get products from sku.io:

use Skuio\Sdk\Sdk;
use Skuio\Sdk\Request;
use Skuio\Sdk\Resource\Products;

public function getProducts()
{
    Sdk::config( [ 'username' => $username, 'password' => $password, 'environment' => Sdk::DEVELOPMENT ] );

    $productsRequest = new Request();
    $productsRequest->setConjunction( 'and' );
    $productsRequest->addFilter( 'sku', '=', '5333180491623' );
    $productsRequest->setLimit( 15 );
    $productsRequest->setPage( 1 );
    
    $products = new Products();
    $products = $products->get( $productsRequest );
    
    return $products->getResponse();
}

And you can use the base Sdk class

use Skuio\Sdk\Sdk;

public function testConnection()
{
    Sdk::config( [ 'username' => $username, 'password' => $password, 'environment' => Sdk::DEVELOPMENT ] );

    $sdk = new Sdk();
    $res = $sdk->authorizedRequest( '/vendors' );
    
    return $res->getResponse();
}
Clone this wiki locally