PHP SDK Sample: Download Coupons

Sample Code
<?php

require_once __DIR__ . '/vendor/autoload.php';

// Configure API key authorization: ultraCartSimpleApiKey
ultracart\v2\Configuration::getDefaultConfiguration()->setApiKey('x-ultracart-simple-key', 'YOUR_SIMPLE_KEY_HERE');

// Disable SSL verification if we're having issues with this PHP install not having the proper CA installed.  Fix your CA for a production environment!
// Set debug to true if you need more information on request/response
$client = new GuzzleHttp\Client(['verify' => false, 'debug' => false]);

$api_instance = new ultracart\v2\api\CouponApi(
    $client,
    ultracart\v2\Configuration::getDefaultConfiguration(),
    new ultracart\v2\HeaderSelector("2016-10-01")
);

$_limit = 100; // int | The maximum number of records to return on this one API call. (Maximum 200)
$_offset = 0; // int | Pagination of the record set.  Offset is a zero based index.
$_sort = "merchant_code"; // string | The sort order of the orders.  See Sorting documentation for examples of using multiple values and sorting by ascending and descending.
$_expand = "all"; // string | The object expansion to perform on the result.

$coupon_query = new \ultracart\v2\models\CouponQuery();

for ($_offset = 0; ; $_offset += $_limit) {
    echo 'Pulling offset ' . $_offset . PHP_EOL;
    try {
        $result = $api_instance->getCouponsByQuery($coupon_query, $_limit, $_offset, $_sort, $_expand);

        if ($result->getSuccess()) {
            echo 'Retrieved ' . count($result->getCoupons()) . PHP_EOL;

            for ($i = 0; $i < count($result->getCoupons()); $i++) {

                $coupon = $result->getCoupons()[$i];

                echo $coupon->getMerchantCode() . PHP_EOL;

                // Put your code here to process each of the orders that came back
//                var_dump($coupon);
            }

            // Are we done?
            if (count($result->getCoupons()) < $_limit) {
                echo 'Finished' . PHP_EOL;
                break;
            }
        } else {
            echo 'Failed to retrieve coupons' . PHP_EOL;
            var_dump($result);
            break;
        }
    } catch (Exception $e) {
        echo 'Exception when calling CouponApi->getCoupons: ', $e->getMessage(), PHP_EOL;
    }
}

?>