PHP code example of ultracart / rest_api_v2_sdk_php

1. Go to this page and download the library: Download ultracart/rest_api_v2_sdk_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ultracart / rest_api_v2_sdk_php example snippets


    



eate a Simple Key: https://ultracart.atlassian.net/wiki/spaces/ucdoc/pages/38688545/API+Simple+Key
$simple_key = '109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00';
$api_instance = ultracart\v2\api\OrderApi::usingApiKey($simple_key);

// The UltraCart objects are large.  Very large.  So we have encapsulated the fields in sub objects allowing you to
// only request the sub objects you need.  This is done via the expansion object.   The API docs on the main web site
// have more details about expansions:  https://www.ultracart.com/api/#expansion.html
$_expand = "affiliate,affiliate.ledger,auto_order,billing,buysafe,channel_partner,checkout,coupon,customer_profile,digital_order,edi,fraud_score,gift,gift_certificate,internal,item,linked_shipment,marketing,payment,payment.transaction,quote,salesforce,shipping,summary,taxes"; // string | The object expansion to perform on the result.

// this is a detailed example that .length: " . sizeof($order_response->getOrders()) . "\n";
        // print out a line for each order *item*
        // notice, email is within the billing child object.
        foreach ($order_response->getOrders() as $order) {
            $order_id = $order->getOrderId();
            $email = $order->getBilling()->getEmail(); // notice the email is part of the billing sub object.
            foreach($order->getItems() as $item){
                echo $order_id . ',' . $email . ',' . $item->getMerchantItemId() . ',' . $item->getQuantity() . "\n";
            }
        }
    } while ($order_response->getMetadata()->getResultSet()->getMore());

} catch (Exception $e) {
    echo 'Exception when calling OrderApi->getOrdersByQuery: ', $e->getMessage(), PHP_EOL;
}
echo "</pre></body></html>";

ultracart\v2\Configuration::getDefaultConfiguration()->setMaxRetrySeconds(30);

try {
    $response = $this->client->send($request, $options);
} catch (RequestException $e) {

    // BEGIN Retry Logic
    if($e->getResponse()) {
        $retryAfter = 0;
        if (array_key_exists('Retry-After', $headers)) {
            $retryAfter = intval($headers['Retry-After'][0]);
        }

        if ($statusCode == 429 && $retry && $retryAfter > 0 && $retryAfter <= $this->config->getMaxRetrySeconds()) {
            sleep($retryAfter);
            return $this->getCustomersByQueryWithHttpInfoRetry(false, $customer_query, $_limit, $_offset, $_since, $_sort, $_expand);
        }
    }
    // End Retry Logic

    throw new ApiException(
        "[{$e->getCode()}] {$e->getMessage()}",
        $e->getCode(),
        $e->getResponse() ? $e->getResponse()->getHeaders() : null,
        $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
    );
}


{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/ultracart/rest_api_v2_sdk_php.git"
    }
  ],
  "