Git Product home page Git Product logo

amazon-paapi's Introduction

amazon-paapi

npm version NPM

Amazon Associate Product Advertising API for NodeJs. A PAAPI 5.0 Extension.

A clean wrapper for amazon's NodeJs SDK. Main purpose of this module is to jumpstart development with easy to understand and clean syntax inspired with the amazon scratchpad-like operation.

Amazon Product API

Installation

npm install amazon-paapi --save

Quickstart

const amazonPaapi = require('amazon-paapi');

const commonParameters = {
  AccessKey: '<YOUR  ACCESS  KEY>',
  SecretKey: '<YOUR  SECRET  KEY>',
  PartnerTag: '<YOUR  PARTNER  TAG>', // yourtag-20
  PartnerType: 'Associates', // Default value is Associates.
  Marketplace: 'www.amazon.com', // Default value is US. Note: Host and Region are predetermined based on the marketplace value. There is no need for you to add Host and Region as soon as you specify the correct Marketplace value. If your region is not US or .com, please make sure you add the correct Marketplace value.
};

const requestParameters = {
  ASIN: 'B07H65KP63',
  Resources: [
    'ItemInfo.Title',
    'Offers.Listings.Price',
    'VariationSummary.VariationDimension',
  ],
};

/** Promise */
amazonPaapi
  .GetVariations(commonParameters, requestParameters)
  .then((data) => {
    // do something with the success response.
    console.log(data);
  })
  .catch((error) => {
    // catch an error.
    console.log(error);
  });

Usage

const amazonPaapi = require('amazon-paapi');

const commonParameters = {
  AccessKey: '<YOUR  ACCESS  KEY>',
  SecretKey: '<YOUR  SECRET  KEY>',
  PartnerTag: '<YOUR  PARTNER  TAG>', // yourtag-20
  PartnerType: 'Associates', // Default value is Associates.
  Marketplace: 'www.amazon.com', // Default value is US. Note: Host and Region are predetermined based on the marketplace value. There is no need for you to add Host and Region as soon as you specify the correct Marketplace value. If your region is not US or .com, please make sure you add the correct Marketplace value.
};

Lookup information for a Browse Node. Please see sample script here.

const requestParameters = {
  BrowseNodeIds: ['3040', '3045'],
  LanguagesOfPreference: ['es_US'],
  Resources: ['BrowseNodes.Ancestor', 'BrowseNodes.Children'],
};

/** Promise */
amazonPaapi
  .GetBrowseNodes(commonParameters, requestParameters)
  .then((data) => {
    // do something with the success response.
    console.log(data);
  })
  .catch((error) => {
    // catch an error.
    console.log(error);
  });

Lookup item information for an item. Please see sample script here.

Note: This operation only supports ASIN as id Type. If you need to lookup using UPC or EAN, you can do so under SearchItems operation.

const requestParameters = {
  ItemIds: ['B00X4WHP5E', 'B00ZV9RDKK'],
  ItemIdType: 'ASIN',
  Condition: 'New',
  Resources: [
    'Images.Primary.Medium',
    'ItemInfo.Title',
    'Offers.Listings.Price',
  ],
};

/** Promise */
amazonPaapi
  .GetItems(commonParameters, requestParameters)
  .then((data) => {
    // do something with the success response.
    console.log(data);
  })
  .catch((error) => {
    // catch an error.
    console.log(error);
  });

Lookup information for variations. Please see sample script here.

const requestParameters = {
  ASIN: 'B07H65KP63',
  Resources: [
    'Images.Primary.Medium',
    'ItemInfo.Title',
    'Offers.Listings.Price',
    'VariationSummary.VariationDimension',
  ],
};

/** Promise */
amazonPaapi
  .GetVariations(commonParameters, requestParameters)
  .then((data) => {
    // do something with the success response.
    console.log(data);
  })
  .catch((error) => {
    // catch an error.
    console.log(error);
  });

Searches for items on Amazon. Please see sample script here.

const requestParameters = {
  Keywords: 'Harry Potter',
  SearchIndex: 'Books',
  ItemCount: 2,
  Resources: [
    'Images.Primary.Medium',
    'ItemInfo.Title',
    'Offers.Listings.Price',
  ],
};

/** Promise */
amazonPaapi
  .SearchItems(commonParameters, requestParameters)
  .then((data) => {
    // do something with the success response.
    console.log(data);
  })
  .catch((error) => {
    // catch an error.
    console.log(error);
  });
  • AccessKey - An alphanumeric token that uniquely identifies you. For information about getting an Access Key, see Register for Product Advertising API.
  • SecretKey - A key that is used in conjunction with the Access Key to cryptographically sign an API request. To retrieve your Access Key or Secret Access Key, refer Register for Product Advertising API.
  • PartnerTag - An alphanumeric token that uniquely identifies a partner. In case of an associate, this token is the means by which Amazon identifies the Associate to credit for a sale. If the value for PartnerType is Associate, specify the store ID or tracking ID of a valid associate store from the requested marketplace as the value for PartnerTag. For example, If store-20 and store-21 are store id or tracking id of customer in United States and United Kingdom marketplaces respectively, then customer needs to pass store-20 as PartnerTag in all PAAPI requests for United States marketplace and store-21 as PartnerTag in all PAAPI requests for United Kingdom marketplace. To obtain an Partner Tag, see Sign up as an Amazon Associate.
  • PartnerType - The type of Amazon program. For more information on valid values, refer PartnerType Parameter.
  • Marketplace - Default value is US. Note: Host and Region are predetermined based on the marketplace value. There's is no need for you to add Host and Region as soon as you specify correct Marketplace value. If your region is not US or .com, please make sure you add the correct Marketplace value.

V4.0 to V5.0 Mapping

Due to major change from V4.0 to V5.0, most of the legacy application may not work properly since V4.0 is not supported anymore.

We're currently working on mapping some commonly used operations from the V4.0 and make it available soon to work with the V5.0.

In the mean time, please check amazon documentation on how to map.

FAQ

  • What are the available resources I can add in the parameter? Please refer to this page.

  • How can I do itemLookup using a UPC or EAN? You can lookup using searchItems operation. Add your UPC or EAN under the keyword parameter. More details here.

  • What if I included an invalid ASIN value in ASIN array parameter? You will get an error response but the result of the valid ASINs are still included in the response data. Please refer to the last portion of this page.

  • Is the addCart Operation still supported in V5.0? It is deprecated, But you can use Add to Cart form to integrate cart on your websites.

Donation

If this somehow makes your job a bit easier, please consider dropping few bucks. Your contribution allows me to spend more time improving features of this project.

Donate

License

MIT

amazon-paapi's People

Contributors

ahmedamshir avatar alexpalaz avatar jorgerosal avatar viesis avatar zl-0627 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

amazon-paapi's Issues

TotalCount not working on SearchItems Method

Maybe it's something I'm doing, but I can't get TotalCount to have any effect on the response of the call. I always get 10 results back regardless of if I leave TotalCount out, set it to 2, or set it to 20. It works if I do it through the Amazon Scratchpad.

Typescript support

Hi, I'm trying to use your package with typescript but I could not find anywhere something like @types/amazon-paapi.
How should I find those ans install via npm?

401 error

Hi, thank you very much for creating this script. I was trying to use it but I get this error:

status: 401,
text: '{"__type":"com.amazon.paapi5#UnrecognizedClientException","Errors":[{"Code":"UnrecognizedClient","Message":"The Access Key ID or security token included in the request is invalid."}]}',
method: 'POST',
path: '/paapi5/searchitems'

I tested the credentials on amazon Scratchpad and they work regularly.

how can i solve?
everything is hosted on a raspberry pi3.

thanks a lot

implement in vue project

CIao I am trying to implement the package in a VUE project, but I get this errors:

ERROR in ./node_modules/amazon-paapi/SDK/src/index.js
Module not found: Error: Can't resolve 'model/GetItemsRequest' in 'C:\Users\Desktop\appVue\amazon-api\node_modules\amazon-paapi\SDK\src'
Did you mean './model/GetItemsRequest'?

lots of error
can you help me?

(doc issue) "Resource" in requestParameters should be "Resources", right?

Hello Jorge,

Not really an issue to be corrected, but I´ve turned around for some hours trying to figure out why the image URL and other resources were not returned.

I started from your doc and the samples you provide. There you use a "Resource" parameter in "requestParameters" when calling.

Testing randomly I changed that to "Resources" and then it worked.

Maybe you want to update the examples and doc, so that others don´t get confused.

Many thanks in any case for this library. Very easy to use and intuitive!

Daniel

TooManyRequestsException - Again..

Hey guys i'm having the same issue as described here:
#8

Sure i did change the Marketplace to my requirements = 'www.amazon.de'

I also did some research where i read, that amazon seems to balance those requests (throttling) partially based on your sales.

I just want to search by API for listed products and their prices (by keyword).

And i'm getting this crappy (sorry) error, already with my first and only request.

Has anybody an idea?

I mean how am i supposed to do anything with that kind of problem, this totally burns my development.

Best regards, Rob.

Response Headers Support

Hi, I'm using this package to get Product details using ASIN. Is there any way to access the response header along with the data?

Too Many Requests

When I try to run the example code (Obviously with my own keys) to search for a Harry Potter book it drops that error. I use the "amazon-pa-api50" and I have no problem when searching with the number of requests
text: '{"__type":"com.amazon.paapi5#TooManyRequestsException","Errors":[{"Code":"TooManyRequests","Message":"The request was denied due to request throttling. Please verify the number of requests made per second to the Amazon Product Advertising API."}]}',

Module not found: Can't resolve 'ApiClient'

./node_modules/amazon-paapi/SDK/src/index.js
Module not found: Can't resolve 'ApiClient'
Did you mean './ApiClient'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, C:\Users\arbal\OneDrive\Desktop\iitm\shopping-web-app).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/amazon-paapi/app.js
./src/app/api/amazonData/route.tsx

these are my codes

const amazonPaapi = require('amazon-paapi');

try {
const data = await amazonPaapi.SearchItems(commonParameters, requestParameters);

console.log(data);

} catch (error) {
// catch an error.
console.log(error);
}

Change on module.exports broke my code in production

We've been using version 1.0.1 for a long time and this version is locked in our package.json. After a deploy this week we realized that the code stopped working.

After a deep review, we found that you have changed app.js:
// Allow use of default import syntax in TypeScript
module.exports.default = amazonPaapi;

You must tag correctly each released version of amazon-paapi, otherwise it can break code in production like ours.

I saw that in this repo there are no tags, would be nice to have that.

1.0.7 doesn't contain the latest commit

Hi,

This module is not working for me because I need its latest commit. The one where you add Belgium to the marketplace.json.

If I yarn add this module it doesn't include that.

bad request (400) when trying to fetch items from multiple marketplaces

I'm trying to fetch the same items from multiple marketplaces but get a 400 bad request error.
sample code:

const commonParameters = {
    AccessKey: 'XXXXXXX',
    SecretKey: 'XXXXXXYYYYYYY',
    PartnerType: 'Associates', // Default value is Associates.
};
const domainParameters = {
        'de': {
            PartnerTag: 'mytag-21', // yourtag-20
            Marketplace: 'www.amazon.de', 
        },
        'fr': {
            PartnerTag: 'mytag-21', // yourtag-20
            Marketplace: 'www.amazon.fr', 
        },
};

function getItems(itemIds) {
      const promisesArr = [];
      Object.values(domainParameters).forEach(domainParam => {
        const amazonPaapi = require('amazon-paapi');
        const commonParams = Object.assign(commonParameters, domainParam);
        const requestParams = Object.assign({ ItemIds: itemIds }, requestParameters);
        promisesArr.push(amazonPaapi
            .GetItems(commonParams, requestParams));
      });
      return promisesArr;
  }

and get the following error

text: '{"__type":"com.amazon.paapi5#InvalidPartnerTagException","Errors":[{"Code":"InvalidPartnerTag","Message":"The partner tag is not mapped to a valid associate store with your access key XXXXXXXX. Please visit associates central at https://partnernet.amazon.de/assoc_credentials/home"}]}',

if I comment out the 'fr' or 'de' config it works, but when running with both, it fails.

Need help with usage

Hello,
I am trying to use the amazon-paapi.
If I call the paapi and print the result to the terminal, I am getting following response.
exports { ItemsResult: exports { Items: [ [exports] ] } }

How can I get and use the api response?
Do you have an example that shows how to call the code and how to get the result in json format?

GetItems - Offers.Listings.MerchantInfo is incorrect with feedback*

Correct Response

"MerchantInfo": {
  "DefaultShippingCountry": "GB",
  "FeedbackCount": 2952,
  "FeedbackRating": 4.87,
  "Id": "A12ZT4ZURPEEJ7",
  "Name": "Peter Pann"
},

Current Response

"MerchantInfo": {
    "DefaultShippingCountry": "GB",
    "Id": "A12ZT4ZURPEEJ7",
    "Name": "Peter Pann"
},

How to use this with Vue.js?

Hello,

I have been trying to work around with amazon new api but i can't get it working with vue.js.

For example, i just created a new Vue project. Added const amazonPaapi = require('amazon-paapi'); in Home.vue file and error.

Failed to compile.
./node_modules/amazon-paapi/SDK/src/index.js
Module not found: Error: Can't resolve 'ApiClient' in 'D:\Apps\Amazon\vue-amazon-paapi\node_modules\amazon-paapi\SDK\src'

http://prntscr.com/s56yiz
https://github.com/sajjadalis/vue-amazon-paapi/blob/master/src/views/Home.vue

I tried official sdk from amazon and amazon paapi wrapper available on github but had similar issues. And It works fine if i add everything inside amazon.js file and try "node amazon.js". I get the response.

I'm not sure if i'm doing something wrong. Is there anyway to properly use this with Vue.js?

Thanks

401 using example code

I'm getting 401 with example script.

const amazonPaapi = require('amazon-paapi');
const ck = require('ckey'); // access .env variables

console.log(ck);

const commonParameters = {
  'AccessKey'  : ck.AWS_ACCESS_KEY,
  'SecretKey'  : ck.AWS_SECRET_KEY,
  'PartnerTag' : ck.AWS_TAG, // yourtag-20
  'PartnerType': 'Associates', //  Default value is Associates. 
  'Marketplace': 'www.amazon.com' // Default value is US. Note: Host and Region are predetermined based on the marketplace value. There is no need for you to add Host and Region as soon as you specify the correct Marketplace value. If your region is not US or .com, please make sure you add the correct Marketplace value.
}

const requestParameters = {
    'Keywords' : 'rust programming',
    'SearchIndex' : 'Books',
    'ItemCount' : 2,
    'Resource': ['Images.Primary.Medium', 'ItemInfo.Title', 'Offers.Listings.Price']
};

/** Promise */
amazonPaapi.SearchItems(commonParameters, requestParameters)
    .then(data => {
        // do something with the success response.
        console.log(data);
    })
    .catch(error => {
        // catch an error.
        console.log(error)
    });
      text: '{"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}',
      [Symbol(kCapture)]: false,
      [Symbol(RequestTimeout)]: undefined
    },

Sometimes get timeout 60000ms exceed

Hello,

sometimes get error 60000ms timeout exceed call api every 2 seconds, this error is not from paapi, internet connection is fine, anyone an idea?

querystring module doesn't exist

When deploying to production, it failed because amazon-paapi/SDK/src/ApiClient.js has the line:

module.exports = factory(require('superagent'), require('querystring'));

However, inside package.json there is no querystring module added in "dependencies".

I did 'npm install querystring' on my main project's package.json and it fixed it, but ideally the querystring module should be added as a dependency inside of the amazon-paapi module.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.