AmazonCreatorsAPI (amazon_creators_api v0.3.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.

Get authentication token for the specified region. Uses cached token if available and valid.

Get token cache statistics (for monitoring/debugging).

Functions

clear_token_cache()

Clear the token cache (useful for testing or forced refresh).

default_version(region)

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.

fetch_auth_token(region, client_id, client_secret, version \\ nil)

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. Pass nil to fall back to the region default.

fetch_items(asins, opts \\ [])

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.

get_items(asins, marketplace, partner_tag, access_token, credential_version, resources \\ nil)

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_token(region, client_id, client_secret, version \\ nil)

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.

token_stats()

Get token cache statistics (for monitoring/debugging).