pa-api -- APIs for Amazon Product Advertising API v5 by Golang
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()
fmt.Println("Marketplace:", sv.Marketplace())
fmt.Println("Region:", sv.Region())
fmt.Println("AcceptLanguage:", sv.AcceptLanguage())
fmt.Println("URL:", sv.URL(paapi5.GetItems.Path()))
PA-API information for Japan region.
sv := paapi5.New(paapi5.WithMarketplace(paapi5.LocaleJapan))
fmt.Println("Marketplace:", sv.Marketplace())
fmt.Println("Region:", sv.Region())
fmt.Println("AcceptLanguage:", sv.AcceptLanguage())
fmt.Println("URL:", sv.URL(paapi5.GetItems.Path()))
Create Client Instance
Create default client instance.
client := paapi5.DefaultClient("mytag-20", "AKIAIOSFODNN7EXAMPLE", "1234567890")
fmt.Println("Marketplace:", client.Marketplace())
Create client instance for Japan region.
client := paapi5.New(
paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
"mytag-20",
"AKIAIOSFODNN7EXAMPLE",
"1234567890",
paapi5.WithHttpClient(http.DefaultClient),
)
fmt.Println("Marketplace:", client.Marketplace())
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() {
client := paapi5.New(
paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
"mytag-20",
"AKIAIOSFODNN7EXAMPLE",
"1234567890",
)
q := query.NewGetItems(
client.Marketplace(),
client.PartnerTag(),
client.PartnerType(),
).ASINs([]string{"B07YCM5K55"}).EnableImages().EnableItemInfo().EnableParentASIN()
body, err := client.RequestContext(context.Background(), q)
if err != nil {
fmt.Printf("%+v\n", err)
return
}
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() {
client := paapi5.New(
paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
"mytag-20",
"AKIAIOSFODNN7EXAMPLE",
"1234567890",
)
q := query.NewGetVariations(
client.Marketplace(),
client.PartnerTag(),
client.PartnerType(),
).ASIN("B07YCM5K55").EnableImages().EnableItemInfo().EnableParentASIN()
body, err := client.RequestContext(context.Background(), q)
if err != nil {
fmt.Printf("%+v\n", err)
return
}
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() {
client := paapi5.New(
paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
"mytag-20",
"AKIAIOSFODNN7EXAMPLE",
"1234567890",
)
q := query.NewSearchItems(
client.Marketplace(),
client.PartnerTag(),
client.PartnerType(),
).Search(query.Keywords, "数学ガール").EnableImages().EnableItemInfo().EnableParentASIN()
body, err := client.RequestContext(context.Background(), q)
if err != nil {
fmt.Printf("%+v\n", err)
return
}
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() {
client := paapi5.New(
paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
"mytag-20",
"AKIAIOSFODNN7EXAMPLE",
"1234567890",
)
q := query.NewGetBrowseNodes(
client.Marketplace(),
client.PartnerTag(),
client.PartnerType(),
).BrowseNodeIds([]string{"3040", "3045"}).EnableBrowseNodes()
body, err := client.RequestContext(context.Background(), q)
if err != nil {
fmt.Printf("%+v\n", err)
return
}
res, err := entity.DecodeResponse(body)
if err != nil {
fmt.Printf("%+v\n", err)
return
}
fmt.Println(res.String())
}
Contributors
Many thanks for contributors
Links