Instantly share code, notes, and snippets.

Embed
What would you like to do?
Complete basic working example for using the unifysell API with the PHP SDK. [unifysell Account required]
vendor/
composer.lock

Requirements

You will need a running PHP-7 installation.

Installation

  1. Get the code
    • git clone https://gist.github.com/unifysell-user/4445ccf065a7e81671b1748c0706dd87 unifysell-api-example
    • or download as zip and extract it
  2. Change directory into project cd unifysell-api-example/
  3. Get composer and install requirements sh unifysell-api-install.sh

Usage

run the example by executing the following:

php unifysell-api-get-order.php
{
"require": {
"unifysell/unifysell-sdk-php": "^0.2.4"
}
}
<?php
require_once 'vendor/autoload.php';
require_once 'unifysell-api-prepare-call.php';
$apiInstance = new Unifysell\SDK\Api\OrdersApi(
new GuzzleHttp\Client(),
$config
);
$firstOrder = $apiInstance->getOrder(1);
echo $firstOrder->getData()->getId();
# > 1
echo $firstOrder->getData()->getAmazonOrderId() . ' === ' . $firstOrder->getData()->getMarketplaceId();
# > 403-7788992-6789102 === 403-7788992-6789102
echo $firstOrder->getData()->getDateCreated();
# > 2018-11-11T15:23:15Z
echo $firstOrder->getData()->getStatus();
# > shipped
$secondOrder = $apiInstance->getOrder(2);
echo $secondOrder->getData()->getId();
# > 2
echo $secondOrder->getData()->getEbayOrderId() . ' === ' . $firstOrder->getData()->getMarketplaceId();
# > 161234567891-1456789101112 === 161234567891-1456789101112
echo $secondOrder->getData()->getDateCreated();
# > 2018-11-11T13:22:01Z
echo $secondOrder->getData()->getStatus();
# > paid
#!/bin/bash
curl -sS https://getcomposer.org/installer | php --
php composer.phar require unifysell/unifysell-sdk-php
<?php
require_once 'vendor/autoload.php';
// Authenticate
$keycloakClient = new \Unifysell\OAuth2\Client\Keycloak(
'<client-id>',
'<client-secret>'
);
$accessToken = $keycloakClient->createAccessToken();
// Build config
$config = Unifysell\SDK\Configuration::getDefaultConfiguration()->setApiKey(
'Authorization',
$keycloakClient->getAccessToken()->getToken()
);
$config->setApiKeyPrefix('Authorization', 'Bearer');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment