go-paapi
Go SDK for Amazon product advertising. It talks to Creators API only — Amazon's replacement for the retired Product Advertising API 5 (PA-API).
The Laravel counterpart is tims/laravel-paapi. Use that in Laravel apps; use this package in Go.
PA-API 5 was not updated in place. Amazon deprecated it and replaced it with Creators API. Old webservices.amazon.* calls now return HTTP 403. See the PA-API 5 deprecation notice.
Requirements
- Go 1.21+
- Amazon Associates Creators API credentials (Credential ID, Secret, Version)
go get github.com/timslabs/go-paapi
Authentication
Create credentials in Associates Central. The SDK fetches an OAuth2 access token and attaches it as Authorization: Bearer {token} (2.x credentials also send , Version {version}).
import (
paapi "github.com/timslabs/go-paapi"
)
client := paapi.NewClient(
os.Getenv("PAAPI_CREDENTIAL_ID"),
os.Getenv("PAAPI_CREDENTIAL_SECRET"),
os.Getenv("PAAPI_CREDENTIAL_VERSION"), // e.g. 3.1
)
client.SetPartnerTag(os.Getenv("PAAPI_PARTNER_TAG"))
client.SetMarketplace("www.amazon.com")
// Token is fetched automatically on the first authenticated call.
// Or authenticate explicitly:
if err := client.Authenticate(); err != nil {
log.Fatal(err)
}
Or manage the token yourself:
client := paapi.NewClientWithToken(os.Getenv("PAAPI_ACCESS_TOKEN"), "3.1")
| Region |
Version |
Token endpoint |
Marketplaces |
| NA |
3.1 (or 2.1) |
api.amazon.com/auth/o2/token |
US, CA, MX, BR |
| EU |
3.2 (or 2.2) |
api.amazon.co.uk/auth/o2/token |
UK, DE, FR, IT, ES, NL, BE, EG, IN, IE, PL, SA, SE, TR, AE |
| FE |
3.3 (or 2.3) |
api.amazon.co.jp/auth/o2/token |
JP, SG, AU |
3.x uses Login with Amazon (JSON body). 2.x uses Cognito (form-encoded). Tokens are cached in memory until shortly before expiry.
Quick start
package main
import (
"fmt"
"log"
"os"
paapi "github.com/timslabs/go-paapi"
"github.com/timslabs/go-paapi/constants"
)
func main() {
client := paapi.NewClient(
os.Getenv("PAAPI_CREDENTIAL_ID"),
os.Getenv("PAAPI_CREDENTIAL_SECRET"),
os.Getenv("PAAPI_CREDENTIAL_VERSION"),
)
client.SetPartnerTag(os.Getenv("PAAPI_PARTNER_TAG"))
client.SetMarketplace("www.amazon.com")
items, err := client.Catalog.GetItems(map[string]interface{}{
"itemIds": []string{"B0XXXX"},
"resources": []string{
constants.RESOURCE_ITEM_INFO_TITLE,
constants.RESOURCE_IMAGES_PRIMARY_MEDIUM,
constants.RESOURCE_OFFERS_V2_LISTINGS_PRICE,
},
}, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v\n", items)
search, err := client.Catalog.SearchItems(map[string]interface{}{
"keywords": "echo",
"searchIndex": "All",
"itemPage": 1,
}, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v\n", search)
}
Successful responses are map[string]interface{} (decoded JSON). Failed HTTP responses return typed errors from the errors package (BadRequestError, ServerError, AuthError).
All resource methods accept an optional extraHeaders map[string]string as the last argument.
If resources or partnerTag are omitted on catalog calls, the SDK fills the same defaults as tims/laravel-paapi.
Configuration
client := paapi.NewClient(id, secret, version)
client.SetTimeout(60) // seconds
client.SetUserAgent("MyApp/1.0")
client.AddHeaders(map[string]string{
"X-Custom": "value",
})
client.SetPartnerTag("yourtag-20")
client.SetMarketplace("www.amazon.in")
client.SetBaseURL("https://creatorsapi.amazon") // default
Override marketplace on a single call:
resp, err := client.Catalog.SearchItems(map[string]interface{}{
"keywords": "tea",
"searchIndex": "All",
}, map[string]string{"x-marketplace": "www.amazon.in"})
Base URL: https://creatorsapi.amazon
API groups
| Resource |
Coverage |
Catalog |
GetItems, SearchItems, GetVariations, GetBrowseNodes |
Feed |
List feeds, get feed download URL |
Report |
List reports, get report download URL |
Package layout
go-paapi/
client.go # NewClient, resource wiring
version.go
constants/ # URLs, headers, status codes, resource strings
errors/ # BadRequestError, ServerError, AuthError
requests/ # HTTP Post + OAuth2 token manager
resources/ # API resource methods
documents/ # Per-resource usage examples
testdata/ # JSON fixtures for tests
utils/ # Test helpers
Tests
go test ./...
go test ./... -v
go test ./resources -run TestCatalogGetItems -v
License
MIT