Skip to content

Fix silent API failures, regional OAuth, pagination, and config permissions - #4

Merged
cprice70 merged 6 commits into
mainfrom
users/cprice/multi-status-errors
Oct 13, 2026
Merged

cprice70 merged 6 commits into
mainfrom
users/cprice/multi-status-errors

Conversation

@cprice70

Copy link
Copy Markdown
Owner

Summary

Fixes from a review pass over the CLI. Each is its own commit with tests written first.

  • 207 Multi-Status handling — Amazon's batch create/update/delete endpoints return 207 with per-item success/error arrays. The client treated any OK status as success, so keywords update-bid, campaigns create, and campaigns archive printed success even when Amazon rejected the item. The client now throws with each item's errorType and errorValue.
  • Regional Login with Amazon endpoints — consent and token URLs were hardcoded to NA, so EU/FE advertisers could not complete auth login. New src/lwa.ts holds the per-region hosts from Amazon's authorization-grants docs. Region (and sandbox) are now asked before the browser opens. Unknown region values fail instead of silently using NA.
  • Campaign performance filter — campaigns performance --campaign X fell back to every campaign's rows when X had no data. Returns an empty result now.
  • Pagination — list endpoints for campaigns, keywords, product ads, and portfolios follow nextToken and merge pages. --json shape is unchanged.
  • Config permissions — config.json holds the client secret and refresh token. Directory is now 0700, file 0600, tightened on every save.
  • Housekeeping — drop unused axios, fix clean script (build/ not dist/), ignore .claude/worktrees/, fix .env.example to list the variables the CLI actually reads.

Test plan

  • npm test — 49 tests pass (18 new, including the first tests for AmazonAdsClient)
  • npm run build clean
  • amazonads auth login end to end against a real EU or FE account (no test account available here)

Amazon's v3/v4 batch endpoints (create/update/delete) return 207 with
per-item success and error arrays in the body. The client treated any OK
status as success, so keyword bid updates, campaign creates, and archives
printed a success message even when Amazon rejected the item.

makeRequest now scans OK response bodies for a non-empty error array and
throws with the errorType and errorValue for each rejected item.
The consent page and token service were hardcoded to the North America
hosts, so EU and FE advertisers could not complete auth login. Region
was also only asked for after the browser flow, too late to pick the
right consent host.

Add src/lwa.ts with the per-region consent and token URLs from Amazon's
authorization-grants docs, ask for region (and sandbox) before opening
the browser, and refresh access tokens against the regional token host.
Region input is now validated; an unknown value fails instead of
silently falling back to NA.
getCampaignPerformance filtered the report to the requested campaign but
fell back to the unfiltered report when nothing matched, so a typo'd or
inactive campaign ID silently showed every campaign in the account.
Return the filtered rows as-is; the command already prints
"No performance data found." for an empty result.
The v3/v4 list endpoints page their results and return a nextToken when
more remain. The client only ever requested the first page, so accounts
with more entities than one page holds got silently truncated lists.

Add a listAll helper that re-posts the same filters with each nextToken
and merges the pages under the entity key, so --json output keeps the
same shape as a single-page response.
config.json stores the client secret and refresh token but was written
with the default umask, typically world-readable. Create the directory
0700 and the file 0600, and chmod both on every save so an existing
file left over from an older version is tightened as well.
- Remove axios; nothing imports it, the client uses fetch.
- Point the clean script at build/, the actual tsc outDir, not dist/.
- Ignore .claude/worktrees/ so session worktrees never get committed.
- Fix .env.example: drop AMAZON_ADS_API_ENDPOINT, which the CLI never
  reads, and document REGION, SANDBOX, and PROFILE_ID, which it does.
@cprice70
cprice70 merged commit 249e259 into main Oct 13, 2026
2 checks passed
@cprice70
cprice70 deleted the users/cprice/multi-status-errors branch October 13, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant