AmazonCreatorsAPI (amazon_creators_api v0.5.0)
Client for Amazon Creators API to fetch product details by ASIN. Supports all regions (NA, EU, FE) with automatic token caching.
Summary
Functions
Clear the token cache (useful for testing or forced refresh).
The credential version Amazon issued for a region before Login with Amazon v3.0. Used when no explicit version is given.
Internal function to fetch authentication token (used by TokenManager). For direct use, prefer get_token/4 which uses caching.
Convenience function to get items with automatic token management. Recommended for most use cases - handles token caching automatically.
Fetch item details by ASIN(s).
Get authentication token for the specified region. Uses cached token if available and valid.
Whether a credential version authenticates against Login with Amazon.
Get token cache statistics (for monitoring/debugging).
Functions
Clear the token cache (useful for testing or forced refresh).
The credential version Amazon issued for a region before Login with Amazon v3.0. Used when no explicit version is given.
Returns nil for an unknown region.
Internal function to fetch authentication token (used by TokenManager). For direct use, prefer get_token/4 which uses caching.
version is the credential version from Associates Central. It selects the
auth flow: 3.x credentials go to Login with Amazon, 2.x ones to Cognito. Pass
nil to fall back to the region default, which is always a 2.x version.
Convenience function to get items with automatic token management. Recommended for most use cases - handles token caching automatically.
Parameters (as keyword list)
- region: :na, :eu, or :fe (default: :na)
- marketplace: Marketplace domain (default: "www.amazon.com")
- partner_tag: Your Amazon Associates tracking ID (required)
- client_id: Your Creators API client ID (required)
- client_secret: Your Creators API client secret (required)
- version: Credential version from Associates Central (optional, defaults to the region's pre-v3.0 version)
- resources: List of resources to retrieve (optional)
Examples
iex> opts = [
...> region: :na,
...> marketplace: "www.amazon.com",
...> partner_tag: "yourpartner-20",
...> client_id: "your_client_id",
...> client_secret: "your_client_secret",
...> version: "3.0"
...> ]
iex> AmazonCreatorsAPI.fetch_items("B09B2SBHQK", opts)
{:ok, %{"itemsResult" => %{"items" => [...]}}}Returns {:ok, items_data} on success or {:error, reason} on failure.
Fetch item details by ASIN(s).
Parameters
- asins: Single ASIN string or list of ASINs
- marketplace: Marketplace domain (e.g., "www.amazon.com")
- partner_tag: Your Amazon Associates tracking ID
- access_token: Access token from get_token/3
- credential_version: Version from get_token/3 response
- resources: List of resources to retrieve (optional)
Examples
iex> {:ok, token_data} = AmazonCreatorsAPI.get_token(:na, client_id, client_secret)
iex> AmazonCreatorsAPI.get_items(
...> "B09B2SBHQK",
...> "www.amazon.com",
...> "yourpartner-20",
...> token_data["access_token"],
...> token_data["version"]
...> )
{:ok, %{"itemsResult" => %{"items" => [...]}}}Returns {:ok, items_data} on success or {:error, reason} on failure.
Get authentication token for the specified region. Uses cached token if available and valid.
Parameters
- region: :na, :eu, or :fe
- client_id: Your Creators API client ID
- client_secret: Your Creators API client secret
- version: Credential version from Associates Central (optional, defaults to the region's pre-v3.0 version)
Examples
iex> AmazonCreatorsAPI.get_token(:na, "your_client_id", "your_client_secret")
{:ok, %{"access_token" => "eyJraWQiOi...", "expires_in" => 3600, "token_type" => "Bearer", "version" => "2.1"}}
iex> AmazonCreatorsAPI.get_token(:na, "your_client_id", "your_client_secret", "3.0")
{:ok, %{"access_token" => "eyJraWQiOi...", "expires_in" => 3600, "token_type" => "Bearer", "version" => "3.0"}}Returns {:ok, token_data} on success or {:error, reason} on failure.
Whether a credential version authenticates against Login with Amazon.
Credentials from v3.0 onwards do; the older 2.x ones use Cognito.
Get token cache statistics (for monitoring/debugging).