Skip to content

Instantly share code, notes, and snippets.

@sawyer
Last active August 29, 2015 14:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sawyer/a74e34280605b62ddc90 to your computer and use it in GitHub Desktop.
Save sawyer/a74e34280605b62ddc90 to your computer and use it in GitHub Desktop.
Paging through all EasyPost Shipments in PHP
<?php
require_once("../lib/easypost.php");
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');
$base_params = array(
"start_datetime" => "2015-07-01",
"end_datetime" => "2015-08-01",
"purchased" => false, // actually means only_purchased?
"page_size" => 10
);
while(!isset($shipments) || $shipments->has_more) {
// add a before_id param to paginate backwards in time
$params = $base_params;
if(isset($shipments)) {
$params = array_merge(
$params,
array("before_id" => $shipments->shipments[count($shipments->shipments)-1]->id)
);
}
$shipments = \EasyPost\Shipment::all($params);
for($i = 0, $j = count($shipments->shipments); $i < $j; $i++) {
var_dump($shipments->shipments[$i]->id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment