Amazon Product Advertising API 5.0 TypeScript SDK

0.2.0 · active · verified Sun Apr 19

The `paapi5-typescript-sdk` is an unofficial TypeScript SDK designed for interacting with Amazon's Product Advertising API 5.0. As of its latest release, v0.2.0, it provides a comprehensive set of classes and types for constructing and sending requests such as `SearchItemsRequest`, `GetItemsRequest`, and `GetBrowseNodesRequest`. The library internally handles the AWS V4 signing process via the `SignHelper` class, abstracting away much of the authentication complexity. Being unofficial, its development and alignment with Amazon's API updates are dependent on the maintainer. It ships with full TypeScript types, making it ideal for type-safe Node.js environments. This SDK simplifies interaction with PAAPI 5.0, which migrated from XML to JSON responses and deprecated PAAPI 4.0 in 2020. While Amazon provides official SDKs for other languages like Python, this TypeScript version fills a gap for Node.js developers seeking a type-safe interface.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate and send a `GetItemsRequest` to Amazon's Product Advertising API 5.0, fetching product details by ASIN.

import { GetItemsRequest, PartnerType, Host, Region } from 'paapi5-typescript-sdk';

async function fetchAmazonProductDetails(asin: string) {
  const partnerTag = process.env.PA_API_PARTNER_TAG ?? 'YOUR_PARTNER_TAG';
  const accessKey = process.env.PA_API_ACCESS_KEY ?? 'YOUR_ACCESS_KEY';
  const secretKey = process.env.PA_API_SECRET_KEY ?? 'YOUR_SECRET_KEY';

  // Ensure you use the correct Host and Region for your desired marketplace
  // e.g., Host.UnitedStates and Region.UNITED_STATES for amazon.com
  const request = new GetItemsRequest(
    {
      ItemIds: [asin],
      Resources: [
        'Images.Primary.Large',
        'ItemInfo.Title',
        'Offers.Listings.Price'
      ],
    },
    partnerTag,
    PartnerType.ASSOCIATES,
    accessKey,
    secretKey,
    Host.Italy, // Example: Using Italy. Change as needed.
    Region.ITALY  // Example: Using Italy. Change as needed.
  );

  try {
    const data = await request.send();
    console.log(`Successfully fetched details for ASIN ${asin}:`);
    console.log(JSON.stringify(data, null, 2));
    return data;
  } catch (error) {
    console.error(`Error fetching details for ASIN ${asin}:`, error);
    throw error;
  }
}

// Example usage (replace with a real ASIN from amazon.it if using Italy locale)
// Make sure to set PA_API_PARTNER_TAG, PA_API_ACCESS_KEY, PA_API_SECRET_KEY
// in your environment variables or replace the placeholders.
fetchAmazonProductDetails('B07WGNF455')
  .then(() => console.log('Product fetch complete.'))
  .catch(() => console.error('Failed to fetch product.'));

view raw JSON →