Last active
August 29, 2015 14:24
-
-
Save sawyer/a74e34280605b62ddc90 to your computer and use it in GitHub Desktop.
Paging through all EasyPost Shipments in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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