Skip to content

Latest commit

History

112 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Test Image 5

Keepa API Framework

This framework is intended for users of the Keepa API.

Requirements

All needed requirements (php version/external libraries) you find in can find in composer.json or on packagist

Features

  • Parses API response to easy to use PHP objects
  • Provides methods that facilitate the work with price history data

Composer

composer require keepa/php_api:*

Examples

Product lookup with price history
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\API\ResponseStatus;
useKeepa\helper\CSVType;
useKeepa\helper\CSVTypeWrapper;
useKeepa\helper\KeepaTime;
useKeepa\helper\ProductAnalyzer;
useKeepa\helper\ProductType;
useKeepa\KeepaAPI;
useKeepa\objects\AmazonLocale;
$api = newKeepaAPI("YOUR_API_KEY");
$r = Request::getProductRequest(AmazonLocale::DE, 0, "2015-12-31", "2018-01-01", 0, true, ['B001G73S50']);
$response = $api->sendRequestWithRetry($r);
switch ($response->status) {
case ResponseStatus::OK:
foreach ($response->productsas$product) {
if ($product->productType == ProductType::STANDARD || $product->productType == ProductType::DOWNLOADABLE) {
// current Amazon price (-1 = out of stock)$currentAmazonPrice = ProductAnalyzer::getLast(
$product->csv[CSVType::AMAZON],
CSVTypeWrapper::getCSVTypeFromIndex(CSVType::AMAZON)
);
if ($currentAmazonPrice == -1) {
echo"{$product->asin}{$product->title} is currently out of stock" . PHP_EOL;
} else {
echo"{$product->asin}{$product->title} — Amazon price: {$currentAmazonPrice}" . PHP_EOL;
}
// weighted mean over the last 90 days$weightedMean90 = ProductAnalyzer::calcWeightedMean(
$product->csv[CSVType::AMAZON],
KeepaTime::nowMinutes(),
90,
CSVTypeWrapper::getCSVTypeFromIndex(CSVType::AMAZON)
);
echo"90-day weighted mean: {$weightedMean90}" . PHP_EOL;
// product imagesif (!empty($product->images)) {
echo"Main image: https://m.media-amazon.com/images/I/{$product->images[0]->l}" . PHP_EOL;
}
// alternate formats (books)if (!empty($product->formats)) {
foreach ($product->formatsas$fmt) {
echo"Also available as: {$fmt->format} — ASIN {$fmt->asin}" . PHP_EOL;
}
}
}
}
break;
default:
print_r($response);
}
Product lookup with offers and buy box stats
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\KeepaAPI;
useKeepa\objects\AmazonLocale;
$api = newKeepaAPI("YOUR_API_KEY");
// request with 20 offers and buy box stats for the last year$r = Request::getProductRequest(
AmazonLocale::DE,
20, // number of offers to retrieve"2024-01-01", // stats start date"2024-12-31", // stats end date0,
true,
['B001G73S50'],
["buybox" => 1]
);
$response = $api->sendRequestWithRetry($r);
if ($response->status === "OK") {
$product = $response->products[0];
$stats = $product->stats;
echo"Buy box price: {$stats->buyBoxPrice}" . PHP_EOL;
echo"Buy box seller: {$stats->buyBoxSellerId}" . PHP_EOL;
echo"Is FBA: " . ($stats->buyBoxIsFBA ? "yes" : "no") . PHP_EOL;
// sale/discount infoif ($stats->buyBoxSavingBasisType !== null) {
echo"Discount type: {$stats->buyBoxSavingBasisType}" . PHP_EOL;
echo"Discount: {$stats->buyBoxSavingPercentage}%" . PHP_EOL;
}
// buy box history per sellerif (!empty($stats->buyBoxStats)) {
foreach ($stats->buyBoxStatsas$sellerId => $bbStats) {
echo"Seller {$sellerId} won buy box {$bbStats->percentageWon}% of the time" . PHP_EOL;
}
}
// live offersif (!empty($product->offers)) {
foreach ($product->offersas$offer) {
echo"Offer: {$offer->sellerId}{$offer->offerCSV[0]} (FBA: " . ($offer->isFBA ? "yes" : "no") . ")" . PHP_EOL;
}
}
}
Product Finder
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\KeepaAPI;
useKeepa\objects\AmazonLocale;
useKeepa\objects\ProductFinderRequest;
$api = newKeepaAPI("YOUR_API_KEY");
// find products between €10 and €50 with an active coupon$finder = newProductFinderRequest();
$finder->avg1_AMAZON_gte = 1000; // prices in cents$finder->avg1_AMAZON_lte = 5000;
$finder->couponOneTimeAbsolute_gte = 1;
$response = $api->sendRequestWithRetry(Request::getFinderRequest(AmazonLocale::DE, $finder));
if ($response->status === "OK") {
echo"Found " . count($response->asinList) . " ASINs" . PHP_EOL;
// fetch full product data for the first result$productResponse = $api->sendRequestWithRetry(
Request::getProductRequest(AmazonLocale::DE, 0, null, null, 0, true, [$response->asinList[0]])
);
if ($productResponse->status === "OK") {
$product = $productResponse->products[0];
echo"{$product->asin}: {$product->title}" . PHP_EOL;
if (!empty($product->coupon)) {
echo"Coupon: {$product->coupon[1]} cents off" . PHP_EOL;
}
if (!empty($product->couponHistory)) {
echo"Coupon history entries: " . (count($product->couponHistory) / 3) . PHP_EOL;
}
}
}
Seller lookup
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\KeepaAPI;
useKeepa\objects\AmazonLocale;
$api = newKeepaAPI("YOUR_API_KEY");
// request seller with storefront ASIN list$response = $api->sendRequestWithRetry(
Request::getSellerRequest(AmazonLocale::DE, ["A8KICS1PHF7ZO"], true)
);
if ($response->status === "OK") {
$seller = $response->sellers["A8KICS1PHF7ZO"];
echo"Seller: {$seller->sellerName}" . PHP_EOL;
echo"FBA: " . ($seller->hasFBA ? "yes" : "no") . PHP_EOL;
echo"Total storefront ASINs: " . end($seller->totalStorefrontAsins) . PHP_EOL;
echo"Buy box win rate (new): {$seller->buyBoxNewOwnershipRate}%" . PHP_EOL;
echo"Avg. buy box competitors: {$seller->avgBuyBoxCompetitors}" . PHP_EOL;
// top competitorsif (!empty($seller->competitors)) {
echo"Top competitors:" . PHP_EOL;
foreach ($seller->competitorsas$competitor) {
echo"{$competitor->sellerId}{$competitor->percent}% shared listings" . PHP_EOL;
}
}
}
Top sellers
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\KeepaAPI;
useKeepa\objects\AmazonLocale;
$api = newKeepaAPI("YOUR_API_KEY");
$response = $api->sendRequestWithRetry(Request::getTopSellerRequest(AmazonLocale::DE));
if ($response->status === "OK") {
echo"Top sellers on Amazon.de:" . PHP_EOL;
foreach ($response->sellerIdListas$sellerId) {
echo"{$sellerId}" . PHP_EOL;
}
}
Category lookup with statistics
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\KeepaAPI;
useKeepa\objects\AmazonLocale;
$api = newKeepaAPI("YOUR_API_KEY");
$response = $api->sendRequestWithRetry(
Request::getCategoryLookupRequest(AmazonLocale::DE, false, "528966011")
);
if ($response->status === "OK") {
$category = reset($response->categories);
echo"Category: {$category->name}" . PHP_EOL;
echo"Avg. buy box price (current): {$category->avgBuyBox}" . PHP_EOL;
echo"Avg. buy box price (90d): {$category->avgBuyBox90}" . PHP_EOL;
echo"Avg. rating: " . ($category->avgRating / 10) . " stars" . PHP_EOL;
echo"Avg. review count: {$category->avgReviewCount}" . PHP_EOL;
echo"FBA percentage: {$category->isFBAPercent}%" . PHP_EOL;
echo"Sold by Amazon: {$category->soldByAmazonPercent}%" . PHP_EOL;
echo"Active sellers: {$category->sellerCount}" . PHP_EOL;
echo"Distinct brands: {$category->brandCount}" . PHP_EOL;
}
Tracking notifications
<?phprequire_once"vendor/autoload.php";
useKeepa\API\Request;
useKeepa\KeepaAPI;
useKeepa\helper\CSVType;
$api = newKeepaAPI("YOUR_API_KEY");
// retrieve all unread notifications$response = $api->sendRequestWithRetry(
Request::getTrackingNotificationRequest(0, false)
);
if ($response->status === "OK" && !empty($response->notifications)) {
foreach ($response->notificationsas$notification) {
echo"ASIN: {$notification->asin}{$notification->title}" . PHP_EOL;
echo"Triggered CSV type: {$notification->csvType}" . PHP_EOL;
if (!empty($notification->currentPrices)) {
$price = $notification->currentPrices[CSVType::AMAZON] ?? null;
if ($price !== null && $price !== -1) {
echo"Current Amazon price at notification: {$price}" . PHP_EOL;
}
}
}
} else {
echo"No new notifications." . PHP_EOL;
}

About

Keepa.com API PHP Framework

Resources

Stars

57 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages