Kroger
Search products, add to cart, and find store locations via the Kroger public API.
Prerequisites
- - Kroger developer account at https://developer.kroger.com
- Registered application with Product and Cart API access
- OAuth redirect URI configured in the Kroger app settings
Environment Variables
Set these before using:
CODEBLOCK0
Optional:
- -
KROGER_TOKEN_FILE — token storage path (default: ~/.kroger-tokens.json) - INLINECODE2 — OAuth callback URL (default:
http://localhost:8888/callback) - INLINECODE4 — store ID for location-specific product availability
Setup (One-Time)
1. Register a Kroger Developer App
- 1. Go to https://developer.kroger.com
- Create an application
- Enable Product and Cart scopes
- Set redirect URI to INLINECODE5
- Note Client ID and Client Secret
2. Authenticate
Run the auth flow — opens a browser for Kroger login:
CODEBLOCK1
If the redirect URI isn't localhost (e.g., cloud-hosted), use the manual flow:
- 1. Open the
AUTH_URL printed by INLINECODE7 - Log in at Kroger
- Copy the redirected URL (even if the page errors)
- Extract the
code parameter and run:
CODEBLOCK2
Tokens auto-refresh. Re-auth only needed if refresh token expires.
Actions
Search products
CODEBLOCK3
Returns up to 5 results with product IDs, descriptions, and brands.
Add to cart
CODEBLOCK4
Requires prior OAuth login. Quantity defaults to 1.
Find nearby stores
CODEBLOCK5
Returns up to 5 stores with location IDs. Set KROGER_LOCATION_ID to filter product search by store.
Check auth status
CODEBLOCK6
Workflow: Grocery List → Cart
Typical flow for adding a grocery list to Kroger:
- 1. Search each item: INLINECODE10
- Pick the best match from results
- Add to cart: INLINECODE11
- Repeat for all items
When adding many items, batch all searches first, then confirm selections with the user, then add all to cart.
Kroger
通过 Kroger 公共 API 搜索商品、添加到购物车以及查找门店位置。
前置条件
- - 在 https://developer.kroger.com 拥有 Kroger 开发者账号
- 已注册应用并开通 Product 和 Cart API 访问权限
- 在 Kroger 应用设置中配置 OAuth 重定向 URI
环境变量
使用前请设置以下变量:
bash
export KROGERCLIENTID=your-client-id
export KROGERCLIENTSECRET=your-client-secret
可选变量:
- - KROGERTOKENFILE — 令牌存储路径(默认:~/.kroger-tokens.json)
- KROGERREDIRECTURI — OAuth 回调 URL(默认:http://localhost:8888/callback)
- KROGERLOCATIONID — 门店 ID,用于按门店筛选商品库存
设置(一次性操作)
1. 注册 Kroger 开发者应用
- 1. 访问 https://developer.kroger.com
- 创建应用
- 启用 Product 和 Cart 权限范围
- 将重定向 URI 设置为 http://localhost:8888/callback
- 记录客户端 ID 和客户端密钥
2. 身份验证
运行身份验证流程 — 将打开浏览器进行 Kroger 登录:
bash
scripts/kroger.sh auth
如果重定向 URI 不是 localhost(例如云托管环境),请使用手动流程:
- 1. 打开 scripts/kroger.sh auth 打印的 AUTH_URL
- 在 Kroger 登录
- 复制重定向后的 URL(即使页面报错)
- 提取 code 参数并运行:
bash
scripts/kroger.sh exchange
令牌会自动刷新。仅在刷新令牌过期时才需要重新认证。
操作
搜索商品
bash
scripts/kroger.sh search cannellini beans
最多返回 5 条结果,包含商品 ID、描述和品牌信息。
添加到购物车
bash
scripts/kroger.sh add [quantity]
需要先完成 OAuth 登录。数量默认为 1。
查找附近门店
bash
scripts/kroger.sh locations
最多返回 5 家门店及其位置 ID。设置 KROGERLOCATIONID 可按门店筛选商品搜索结果。
检查认证状态
bash
scripts/kroger.sh token
工作流程:购物清单 → 购物车
将购物清单添加到 Kroger 的典型流程:
- 1. 搜索每件商品:scripts/kroger.sh search
- 从结果中选择最佳匹配
- 添加到购物车:scripts/kroger.sh add
- 对所有商品重复上述步骤
添加大量商品时,建议先批量完成所有搜索,然后与用户确认选择,最后将所有商品一次性添加到购物车。