Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Amazon Paa Laravel Package

caponica/amazon-paa

PHP client for Amazon Product Advertising API (PAA). Helps build signed requests and fetch product data (items, offers, images, etc.) for affiliate-style integrations. Lightweight package aimed at simple API consumption and response handling.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require caponica/amazon-paa
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        Caponica\AmazonPAA\AmazonPAAServiceProvider::class,
    ],
    
  2. Configuration Publish the config file:

    php artisan vendor:publish --provider="Caponica\AmazonPAA\AmazonPAAServiceProvider"
    

    Update config/amazon-paa.php with your:

    • AWS Access Key
    • AWS Secret Key
    • Associate Tag
    • Target Marketplace (e.g., US, UK)
  3. First Use Case: Fetch Item Data

    use Caponica\AmazonPAA\Facades\AmazonPAA;
    
    $response = AmazonPAA::itemLookup(['ItemId' => 'B08N5KWBZ2']);
    $items = $response->getItems();
    

Implementation Patterns

Core Workflows

  1. Item Lookup Fetch product details by ASIN, ISBN, or UPC:

    $response = AmazonPAA::itemLookup([
        'ItemId' => ['B08N5KWBZ2', 'B07Q5JQ1X1'],
        'ResponseGroup' => 'ItemAttributes,Images,Offers'
    ]);
    
  2. Search Products

    $response = AmazonPAA::search([
        'Keywords' => 'wireless earbuds',
        'SearchIndex' => 'Electronics',
        'ItemCount' => 10
    ]);
    
  3. Browse Nodes

    $response = AmazonPAA::browseNodeLookup([
        'BrowseNodeId' => '1000',
        'ResponseGroup' => 'Children'
    ]);
    

Integration Tips

  • Rate Limiting: The API enforces 1 request per second. Cache responses aggressively:

    $cacheKey = 'amazon_'.md5(serialize($params));
    return Cache::remember($cacheKey, now()->addMinutes(5), function() use ($params) {
        return AmazonPAA::itemLookup($params);
    });
    
  • Error Handling Wrap calls in try-catch:

    try {
        $response = AmazonPAA::itemLookup(['ItemId' => 'INVALID_ASIN']);
    } catch (\Caponica\AmazonPAA\Exceptions\AmazonPAAException $e) {
        Log::error($e->getMessage());
        return response()->json(['error' => 'Amazon API failed'], 500);
    }
    
  • Pagination Use getNextToken() for paginated results:

    $response = AmazonPAA::search(['Keywords' => 'laptop']);
    while ($response->getNextToken()) {
        $response = AmazonPAA::search([
            'Keywords' => 'laptop',
            'NextToken' => $response->getNextToken()
        ]);
    }
    

Gotchas and Tips

Common Pitfalls

  1. Associate Tag Validation

    • The AssociateTag in config must match the one registered in Amazon’s PAAPI.
    • Test with a small budget first to avoid unexpected charges.
  2. Response Groups

    • Not all ResponseGroup values are supported for every operation. Check Amazon’s docs for valid combinations.
    • Example: Offers requires ItemAttributes in ItemLookup.
  3. Locale-Specific Data

    • The Marketplace config must match the locale of your data (e.g., US for US dollars, UK for GBP).
    • Prices and currencies will reflect the marketplace.
  4. Deprecated Parameters

    • Some parameters (e.g., Version) are ignored in newer API versions. Stick to the latest PAAPI docs.

Debugging Tips

  • Enable Debug Mode Set debug to true in config/amazon-paa.php to log raw API responses:

    'debug' => env('AMAZON_PAA_DEBUG', false),
    
  • Validate XML Responses Use dd($response->getRawResponse()) to inspect raw XML if data is malformed.

  • Common Errors

    • InvalidParameterValue: Check for typos in SearchIndex or ItemId.
    • AWS.AmazonAdvertisingAPI.NoSuchKey: Verify your AssociateTag and credentials.
    • Throttling: Implement exponential backoff for rate limits.

Extension Points

  1. Custom Response Transformers Override the default response handling by binding a custom transformer:

    AmazonPAA::extend(function ($response) {
        return (object) [
            'title' => $response->getItems()[0]->getTitle(),
            'price' => $response->getItems()[0]->getListPrice()->getAmount()
        ];
    });
    
  2. Middleware for API Calls Add middleware to log or modify requests/responses:

    AmazonPAA::middleware(function ($request, $next) {
        Log::info('Amazon PAAPI Request:', $request->getParams());
        return $next($request);
    });
    
  3. Testing Mock the API client for unit tests:

    $mock = Mockery::mock(\Caponica\AmazonPAA\AmazonPAAClient::class);
    $mock->shouldReceive('itemLookup')->andReturn($mockResponse);
    $this->app->instance(\Caponica\AmazonPAA\AmazonPAAClient::class, $mock);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky