PHPackages                             caponica/amazon-rainforest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. caponica/amazon-rainforest

ActiveLibrary

caponica/amazon-rainforest
==========================

Simplified access the Amazon Rainforest API

v0.1-beta(3y ago)5194↓100%2MITPHPPHP &gt;=5.4.0

Since Jun 4Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/caponica/AmazonRainforest)[ Packagist](https://packagist.org/packages/caponica/amazon-rainforest)[ RSS](/packages/caponica-amazon-rainforest/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Complete Amazon Rainforest API
==============================

[](#complete-amazon-rainforest-api)

This is an attempt to wrap and simplify access to the [Rainforest API](https://rainforestapi.com/) for PHP coders

Installation
============

[](#installation)

Install using composer:

```
composer require caponica/amazon-rainforest-api

```

Accessing the API
=================

[](#accessing-the-api)

Your code will look something like this:

```
use CaponicaAmazonRainforest\Client\RainforestClient;
use CaponicaAmazonRainforest\Request\ProductRequest;

$config = [ 'api_key' => 'YOUR_API_KEY' ];
$rfClient = new RainforestClient($config);

$rfRequests = [
    new ProductRequest(RainforestClient::AMAZON_SITE_USA, 'B001234567'),
    // ... can queue up more - they are sent asynchronously ...
];
$rfRequests = $rfClient->prepareRequestArray($requests); // Optional step. De-duplicates the requests and sets keys you can use for local caching.
$apiEntities = $rfClient->retrieveProducts($rfRequests);

foreach ($apiEntities as $key => $rfProduct) {
    // do something with the Product object ...
}

```

The API calls return objects with cleaned up data and sane accessors.

Integrating with your own code
==============================

[](#integrating-with-your-own-code)

The code in this library uses methods to manipulate its objects. This means that you can extend the Rainforest object classes, then pass your versions through to the API and it will use your versions.

For example: We use Symfony and Doctrine in our own main code base. Our Doctrine classes extend the Rainforest ones:

```
namespace Caponica\OurAmazonBundle\Entity;

class RainforestReview extends \CaponicaAmazonRainforest\Entity\RainforestReview {}

```

Then we work with the Rainforest objects like this:

```
// ...

$config = [ 'api_key' => 'YOUR_API_KEY' ];
$rfClient = new RainforestClient($config);

$rfRequests = [
    new ProductRequest(RainforestClient::AMAZON_SITE_USA, 'B001234567'),
];
$rfRequests = $rfClient->prepareRequestArray($requests); // De-duplicates the requests and sets keys you can use for local caching.

$requestsToSendToApi = [];
$rfEntities = $this->retrieveCachedProductsForMarketAsins(array_keys($requests)); // check to see if we already have local copies of any of the objects we're about to pull from the API
foreach ($requests as $key => $request) {
    if (array_key_exists($key, $rfEntities)) {
        if ($this->cachedDataIsFresh($rfEntities[$key], $maxAgeHours)) {
            $this->logVerbose("$key using cached data");
            continue;
        } else {
            $this->logVerbose("$key cached data stale, fetching from API");
        }
    } else {
        $rfEntities[$key] = new RainforestProduct(); // instantiate our version the Product object for each request
        $this->logVerbose("$key not cached, fetching from API");
    }
    $requestsToSendToApi[$key] = $request;
}

$apiEntities = $rfClient->retrieveProducts($requestsToSendToApi, $rfEntities);
// In the line above we pass our versions of the entities to the API in the second argument.
// It will then update them (and use any overridden methods on our version of the classes)
// instead of creating new ones using its own objects.

foreach ($apiEntities as $key => $rfProduct) {
    // do something with the Product object, e.g. persist() it if it's useful  ...
}
$this->em->flush(); // Commit the database changes

```

Logging
=======

[](#logging)

RainforestClient takes an optional Psr\\Log\\LoggerInterface object in its constructor. If you provide one then you can control how messages are output (or discarded).

See  and for more details about setting up a Logger.

A basic Logger (which simply echoes messages), would look like this:

```
# EchoLogger.php

namespace Your\Path;

use Psr\Log\AbstractLogger;

class EchoLogger extends AbstractLogger
{
    /**
     * Logs with an arbitrary level.
     *
     * @param mixed  $level
     * @param string $message
     * @param array  $context
     *
     * @return void
     */
    public function log($level, $message, array $context = array())
    {
        echo "$message\n";
    }
}

```

You then simply pass an EchoLogger instance into the constructor:

```
use CaponicaAmazonRainforest\Client\RainforestClient;
use Your\Path\EchoLogger;

$config = [ ... ];
$echoLogger = new EchoLogger();
$rfClient = new RainforestClient($config, $echoLogger);

```

About the Author
================

[](#about-the-author)

Package created and maintained by Christian Morgan.

I'm a well-established Amazon/e-commerce entrepreneur and co-founder of ScaleForEtail. If you are also an Amazon brand owner or seller then you're welcome to [join the ScaleForEtail community](https://facebook.com/groups/scaleforetail/). We organise [webinars](https://app.livestorm.co/scaleforetail/) and live events for the e-commerce community. In short: we bring like-minded people together.

Drop by and check us out today!

Bugs and Feature Requests
=========================

[](#bugs-and-feature-requests)

If you find something not working as expected please create an issue on github - or a pull request with a fix! This library is open-source and provided free of charge without warranty of any kind. I hope you find it useful!

###  Health Score

29

—

LowBetter than 62% of packages

Maintenance47

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~831 days

Total

2

Last Release

1287d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eccdd6ef9ff663251abf6429bb9104945af2c176da27af50555feedc5b05b184?d=identicon)[caponica](/maintainers/caponica)

---

Top Contributors

[![caponica](https://avatars.githubusercontent.com/u/203801?v=4)](https://github.com/caponica "caponica (65 commits)")

---

Tags

amazonAmazon-apirainforest api

### Embed Badge

![Health badge](/badges/caponica-amazon-rainforest/health.svg)

```
[![Health](https://phpackages.com/badges/caponica-amazon-rainforest/health.svg)](https://phpackages.com/packages/caponica-amazon-rainforest)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k501.4M1.9k](/packages/aws-aws-sdk-php)[jlevers/selling-partner-api

PHP client for Amazon's Selling Partner API

4275.1M1](/packages/jlevers-selling-partner-api)[async-aws/core

Core package to integrate with AWS. This is a lightweight AWS SDK provider by AsyncAws.

10137.8M60](/packages/async-aws-core)[thewirecutter/paapi5-php-sdk

ProductAdvertisingAPI 5.0 PHP SDK

671.7M5](/packages/thewirecutter-paapi5-php-sdk)[amazon-php/sp-api-sdk

Amazon Selling Partner API - PHP SDK

133363.5k1](/packages/amazon-php-sp-api-sdk)[revolution/laravel-amazon-product-api

Amazon Product Advertising API for Laravel

7949.0k](/packages/revolution-laravel-amazon-product-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
