Skip to content
dasliciousPublic

About

Read your own target.com order history: Go library, JSON CLI and MCP server, plus field notes on Target's order APIs

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

target-go

Reads your own target.com order history: online orders, in-store purchases linked to your Target Circle account, and the card charges (invoices) of online orders. It comes as:

  • a Go library (github.com/daslicious/target-go, package target);
  • target-cli, which prints orders as JSON for any language or script;
  • an MCP server (target-cli mcp), so an AI assistant can look up what you bought;
  • PROTOCOL.md, field notes on Target's APIs, for writing a client in another language.

Target has no public API for this. target-go calls the JSON APIs target.com's own order pages use, with a login copied out of your browser, and renews that login on its own: it can run unattended (from cron, a server) for as long as Target keeps the login valid. It is unofficial, it breaks when Target changes those APIs, and it is meant for reading your own orders.

Status: in daily use since 2026-10-11 by itemize (a fork), which writes Target items into Monarch transactions.

Save a login

target-go needs a login no browser keeps using: Target replaces the refresh token on every renewal, and a browser renewing the same login would kill target-go's copy (and the other way round).

  1. In Chrome, open an Incognito window (Ctrl+Shift+N) and sign in at target.com.

  2. Open target.com/orders, then DevTools (F12) → Network, filter history, and reload.

  3. Right-click the history request marked {} (not the empty-box preflight) → Copy → Copy as cURL (bash).

  4. Save it (it is replayed first, and saved only if Target accepts it):

    xclip -o -selection clipboard | target-cli set-session              # Linux
    pbpaste | target-cli set-session                                     # macOS
  5. Close the Incognito window without signing out.

Logins are saved to ~/.config/target-go/session-<account>.json (mode 0600; -account NAME chooses another, TARGET_SESSION_DIR another directory, -session FILE or TARGET_SESSION a file). A fresh sign-in gives a 4-hour access token; each renewal gives 24 hours. Any command renews an expired token before it runs and saves the result right away.

CLI

go install github.com/daslicious/target-go/cmd/target-cli@latest
target-cli status                                # the saved login; no network
target-cli orders -days 30                       # history entries: id, date, total, item names
target-cli orders -since 2026-09-01 -type online -details   # with items, prices, payments, charges
target-cli order 912000000000001                 # one online order with its charges
target-cli order 6000-1234-0000-0001             # one in-store receipt
target-cli raw '/post_orders/v1/orders/history?page_number=1&page_size=10&order_purchase_type=ONLINE'
target-cli refresh                               # renew now (once the access token has expired)

Output is JSON on stdout; logs and warnings go to stderr (-v logs every request). Exit status: 0 ok, 1 error, 2 usage, 3 the login is missing or no longer accepted, 4 Target's bot protection answered (wait an hour or more). Requests are paced 3-5 seconds apart, so -details takes a few seconds per order.

order and orders -details print a Purchase:

{
  "id": "912000000000001", "kind": "online",          // or "store"
  "placed_at": "2026-10-10T17:02:11Z", "date": "2026-10-10",   // date: local calendar day
  "total": 64.18, "subtotal": 61.15, "tax": 4.03,
  "card_charged": 64.18,                               // less gift cards, coupons, after-total discounts
  "items": [{"tcin": "12345678", "name": "Gala Apples - 3lb Bag", "quantity": 2,
             "unit_price": 4.19, "price": 8.38, "product_type": "GROCERY"}],
  "payments": [{"type": "MASTERCARD", "sub_type": "APPLEPAY", "name": "Mastercard", "amount": 64.18, "card": true}],
  "charges": [                                         // online: one per card charge, oldest first
    {"invoice_id": "62000000000000001", "charged_at": "…", "date": "2026-10-10", "total": 41.27,
     "card_charged": 41.27, "payments": […],
     "lines": [{"tcin": "…", "name": "…", "quantity": 1, "amount": 21.54},   // after discounts, with tax
               {"tcin": "…", "name": "PAPER_BAG", "quantity": 2, "amount": 0.20, "fee": true}]}
  ]
}

An online order shipped in parts can be charged once per shipment, so match bank transactions to charges, not to total. In-store receipts are one charge, card_charged.

MCP server

target-cli mcp serves every saved login in the session directory over stdio, with three read-only tools:

Tool What
list_orders orders placed in a period (days, or since/until; kind: online, store or all) with totals and item names
get_order one order or receipt as a Purchase (above)
login_status the saved logins and when their tokens expire, without contacting Target

Every tool takes an optional account (a saved login's name). For Claude Code:

claude mcp add target-orders -- target-cli mcp

Other clients: run target-cli mcp as a stdio server, with TARGET_SESSION_DIR set if the logins aren't in ~/.config/target-go.

Library

client, err := target.Open(path)                     // a saved login; renewals are saved back to it
if err != nil { … }
if _, err := client.EnsureFresh(ctx, 15*time.Minute); err != nil { … }

summaries, complete, err := client.Summaries(ctx, target.ListOptions{Since: time.Now().AddDate(0, 0, -30)})
p, err := client.Purchase(ctx, summaries[0].ID)

// Target's own responses, for fields the Purchase view leaves out:
order, err := client.OnlineOrder(ctx, "912000000000001")
receipt, err := client.StoreOrder(ctx, "6000-1234-0000-0001")
invoices, err := client.Invoices(ctx, "912000000000001")   // invoices.Charges(): the charges, oldest first
raw, err := client.Get(ctx, "/post_orders/v1/912000000000001")

Logins: ParseSession reads a pasted cURL command or Cookie header, SaveSession/LoadSession store it, and Refresh renews it. A client made with Open re-reads the file before renewing and saves the renewal at once, under a lock (<file>.lock) that other programs using the same file take too, so they can share a login on one machine. With NewClient, saving is up to you.

Errors: ErrNotAuthenticated (no login, or Target rejected it, or it can't be renewed), ErrBlocked (bot protection or HTTP 429), ErrNotFound. Requests are paced with WithPacing (default 3 s plus up to 2 s of jitter); WithDumpDir saves every response.

Development

go test -race ./...

The test data is synthetic: Target's response shapes with made-up order numbers and amounts.

License

MIT; see LICENSE.

About

Read your own target.com order history: Go library, JSON CLI and MCP server, plus field notes on Target's order APIs

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages