Git Product home page Git Product logo

paapi5-typescript-sdk's Introduction

paapi5-typescript-sdk

Unofficial TypeScript SDK for Product Advertising API 5.0

Installation

In order to install this SDK, you just have to run you well-known npm or yarn scripts:

npm i -S paapi5-typescript-sdk

Or

yarn add paapi5-typescript-sdk

And there you go! Enjoy ๐Ÿ˜Ž

API

Everything is exported from the SDK: requests' classes, models, utility types, helper and so on..

If you want to import everything

import * as SDK from 'paapi5-typescript-sdk';

And use what you need later

const request = new SDK.SearchItemsRequest(/* ... */);

You can refer to the Amazon Product Advertising API 5.0 for further details about every request

Auth

In order to validate all the requests against the APIs, I've implemented almost from scratch the AWS V4 signing process, creating the SignHelper class.

This is intended for interal use, but if you want to use it for other purposes, here you can find an example:

import { HttpMethod, SignHelper, Region } from 'paapi5-typescript-sdk'

const timestamp = 1609426121130;

const path = '/paapi5/getbrowsenodes';
const method = HttpMethod.POST;
const service = 'ProductAdvertisingAPI';

const accessKey = 'accessKey';
const secretKey = 'secretKey';

const signHelper = new SignHelper(accessKey, secretKey);

const headers = {
    host: 'webservices.amazon.it',
    'x-amz-target': 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.GetBrowseNodes',
    'x-amz-date': signHelper.toAmzDate(timestamp),
    'content-encoding': 'amz-1.0',
    'content-type': 'application/json; charset=utf-8',
};

const header = signHelper.getAuthorizationHeader(path, method, {}, headers, Region.ITALY, service, timestamp);

// 'AWS4-HMAC-SHA256 Credential=accessKey/20201231/eu-west-1/ProductAdvertisingAPI/aws4_request, SignedHeaders=content-encoding;content-type;host;x-amz-date;x-amz-target, Signature=ba741bfb87f9bf3b9b343d72e4f76dc9f169f2e86a047423d783a2169f03c595'

Http

This folder only contains some types, interfaces and enums

Models (resources)

This folder only contains some types, interfaces and enums

Link to Amazon documentation

Requests

Here you can find all the classes you need in order to communicate with the APIs

CommonRequest

This is intended to be just a parent class to be extended by all the other specific classes.

Its only purposes are:

  • Instantiate a SignHelper for internal use
  • Prepare all the request's parameters including the URL, the headers and the payload
  • Abstracts away the send() method so that all the sub-classes don't need to implement it

Example

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

const commonRequest = new CommonRequest(
    'partnerTag',
    PartnerType.ASSOCIATES,
    'accessKey',
    'secretKey',
    Host.Italy,
    Region.Italy
);

// Not an real request, just an example
const data = await commonRequest.send();

GetBrowseNodesRequest

Amazon documentation here

Example

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

const request = new GetBrowseNodesRequest(
    { /* parameters */ }
    'partnerTag',
    PartnerType.ASSOCIATES,
    'accessKey',
    'secretKey',
    Host.Italy,
    Region.Italy
);

const data = await request.send();

GetItemsRequest

Amazon documentation here

Example

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

const request = new GetItemsRequest(
    { /* parameters */ }
    'partnerTag',
    PartnerType.ASSOCIATES,
    'accessKey',
    'secretKey',
    Host.Italy,
    Region.Italy
);

const data = await request.send();

GetVariationsRequest

Amazon documentation here

Example

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

const request = new GetVariationsRequest(
    { /* parameters */ }
    'partnerTag',
    PartnerType.ASSOCIATES,
    'accessKey',
    'secretKey',
    Host.Italy,
    Region.Italy
);

const data = await request.send();

SearchItemsRequest

Amazon documentation here

Example

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

const request = new SearchItemsRequest(
    { /* parameters */ }
    'partnerTag',
    PartnerType.ASSOCIATES,
    'accessKey',
    'secretKey',
    Host.Italy,
    Region.Italy
);

const data = await request.send();

paapi5-typescript-sdk's People

Contributors

pigotz avatar

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.