Skip to content
/ pa-api Public

APIs for Amazon Product Advertising API v5 by Golang

License

Notifications You must be signed in to change notification settings

goark/pa-api

Folders and files

NameName
Last commit message
Last commit date
Feb 3, 2024
Feb 13, 2024
Feb 8, 2024
Sep 29, 2019
Oct 2, 2020
Jul 16, 2021
Aug 12, 2020
Sep 23, 2019
Feb 1, 2024
Feb 3, 2024
Feb 3, 2024
Mar 7, 2021
Oct 14, 2019
Oct 14, 2019
Sep 30, 2019
Mar 14, 2022
Feb 3, 2024
Feb 3, 2024
Dec 8, 2021
Dec 8, 2021
Jul 13, 2022
Mar 14, 2022
Oct 20, 2019
Sep 29, 2019
Sep 29, 2019

Repository files navigation

pa-api -- APIs for Amazon Product Advertising API v5 by Golang

check vulns lint status GitHub license GitHub release

This package is required Go 1.16 or later.

Migrated repository to github.com/goark/pa-api

Usage

Create PA-API Information

Default PA-API information.

sv := paapi5.New() //Create default server
fmt.Println("Marketplace:", sv.Marketplace())
fmt.Println("Region:", sv.Region())
fmt.Println("AcceptLanguage:", sv.AcceptLanguage())
fmt.Println("URL:", sv.URL(paapi5.GetItems.Path()))
// Output:
// Marketplace: www.amazon.com
// Region: us-east-1
// AcceptLanguage: en_US
// URL: https://webservices.amazon.com/paapi5/getitems

PA-API information for Japan region.

sv := paapi5.New(paapi5.WithMarketplace(paapi5.LocaleJapan)) //Create server in Japan region
fmt.Println("Marketplace:", sv.Marketplace())
fmt.Println("Region:", sv.Region())
fmt.Println("AcceptLanguage:", sv.AcceptLanguage())
fmt.Println("URL:", sv.URL(paapi5.GetItems.Path()))
// Output:
// Marketplace: www.amazon.co.jp
// Region: us-west-2
// AcceptLanguage: ja_JP
// URL: https://webservices.amazon.co.jp/paapi5/getitems

Create Client Instance

Create default client instance.

client := paapi5.DefaultClient("mytag-20", "AKIAIOSFODNN7EXAMPLE", "1234567890") //Create default client
fmt.Println("Marketplace:", client.Marketplace())
// Output:
// Marketplace: www.amazon.com

Create client instance for Japan region.

//Create client for Janan region
client := paapi5.New(
    paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
    "mytag-20",
    "AKIAIOSFODNN7EXAMPLE",
    "1234567890",
    paapi5.WithHttpClient(http.DefaultClient),
)
fmt.Println("Marketplace:", client.Marketplace())
// Output:
// Marketplace: www.amazon.co.jp

Sample code

Operation GetItems

package main

import (
    "context"
    "fmt"

    paapi5 "github.com/goark/pa-api"
    "github.com/goark/pa-api/entity"
    "github.com/goark/pa-api/query"
)

func main() {
    //Create client
    client := paapi5.New(
        paapi5.WithMarketplace(paapi5.LocaleJapan),
    ).CreateClient(
        "mytag-20",
        "AKIAIOSFODNN7EXAMPLE",
        "1234567890",
    )

    //Make query
    q := query.NewGetItems(
        client.Marketplace(),
        client.PartnerTag(),
        client.PartnerType(),
    ).ASINs([]string{"B07YCM5K55"}).EnableImages().EnableItemInfo().EnableParentASIN()

    //Requet and response
    body, err := client.RequestContext(context.Background(), q)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    //io.Copy(os.Stdout, bytes.NewReader(body))

    //Decode JSON
    res, err := entity.DecodeResponse(body)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    fmt.Println(res.String())
}

Operation GetVariations

package main

import (
    "context"
    "fmt"

    paapi5 "github.com/goark/pa-api"
    "github.com/goark/pa-api/entity"
    "github.com/goark/pa-api/query"
)

func main() {
    //Create client
    client := paapi5.New(
        paapi5.WithMarketplace(paapi5.LocaleJapan),
    ).CreateClient(
        "mytag-20",
        "AKIAIOSFODNN7EXAMPLE",
        "1234567890",
    )

    //Make query
    q := query.NewGetVariations(
        client.Marketplace(),
        client.PartnerTag(),
        client.PartnerType(),
    ).ASIN("B07YCM5K55").EnableImages().EnableItemInfo().EnableParentASIN()

    //Request and response
    body, err := client.RequestContext(context.Background(), q)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    //io.Copy(os.Stdout, bytes.NewReader(body))

    //Decode JSON
    res, err := entity.DecodeResponse(body)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    fmt.Println(res.String())
}

Operation SearchItems

package main

import (
    "context"
    "fmt"

    paapi5 "github.com/goark/pa-api"
    "github.com/goark/pa-api/entity"
    "github.com/goark/pa-api/query"
)

func main() {
    //Create client
    client := paapi5.New(
        paapi5.WithMarketplace(paapi5.LocaleJapan),
    ).CreateClient(
        "mytag-20",
        "AKIAIOSFODNN7EXAMPLE",
        "1234567890",
    )

    //Make query
    q := query.NewSearchItems(
        client.Marketplace(),
        client.PartnerTag(),
        client.PartnerType(),
    ).Search(query.Keywords, "数学ガール").EnableImages().EnableItemInfo().EnableParentASIN()

    //Request and response
    body, err := client.RequestContext(context.Background(), q)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    //io.Copy(os.Stdout, bytes.NewReader(body))

    //Decode JSON
    res, err := entity.DecodeResponse(body)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    fmt.Println(res.String())
}

Operation GetBrowseNodes

package main

import (
    "context"
    "fmt"

    paapi5 "github.com/goark/pa-api"
    "github.com/goark/pa-api/entity"
    "github.com/goark/pa-api/query"
)

func main() {
    //Create client
    client := paapi5.New(
        paapi5.WithMarketplace(paapi5.LocaleJapan),
    ).CreateClient(
        "mytag-20",
        "AKIAIOSFODNN7EXAMPLE",
        "1234567890",
    )

    //Make query
    q := query.NewGetBrowseNodes(
        client.Marketplace(),
        client.PartnerTag(),
        client.PartnerType(),
    ).BrowseNodeIds([]string{"3040", "3045"}).EnableBrowseNodes()

    //Request and response
    body, err := client.RequestContext(context.Background(), q)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }

    //Decode JSON
    res, err := entity.DecodeResponse(body)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    fmt.Println(res.String())
}

Contributors

Many thanks for contributors

Links