jackwener/OpenCLI · error · ArgumentError

Either --product-id or --url is required

Error message

Either --product-id or --url is required

What it means

This ArgumentError is a client-side precondition check in the coupang add-to-cart command: the caller must supply either --product-id or --url so the command can determine which product to add. If both are absent there is no way to build the target product URL, so the command fails fast before any browser navigation. Note that when only --product-id is given, --url may be omitted (the URL is derived).

Source

Thrown at clis/coupang/add-to-cart.js:111

  `;
}
cli({
    site: 'coupang',
    name: 'add-to-cart',
    access: 'write',
    description: 'Add a Coupang product to cart using logged-in browser session',
    domain: 'www.coupang.com',
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        { name: 'product-id', positional: true, required: false, help: 'Coupang product ID' },
        { name: 'url', required: false, help: 'Canonical product URL' },
    ],
    columns: ['ok', 'product_id', 'url', 'message'],
    func: async (page, kwargs) => {
        const rawProductId = kwargs['product-id'];
        if (!rawProductId && !kwargs.url) {
            throw new ArgumentError('Either --product-id or --url is required');
        }
        const productId = rawProductId
            ? requireProductIdArg(rawProductId, 'product-id')
            : requireProductIdArg(kwargs.url, '--url');
        const targetUrl = canonicalizeProductUrl(kwargs.url, productId);
        const finalUrl = targetUrl || canonicalizeProductUrl('', productId);
        await page.goto(finalUrl).catch((error) => {
            throw new CommandExecutionError(`coupang add-to-cart navigation failed: ${error?.message || error}`);
        });
        const result = await page.evaluate(buildAddToCartEvaluate(productId)).catch((error) => {
            throw new CommandExecutionError(`coupang add-to-cart evaluation failed: ${error?.message || error}`);
        });
        const loginHints = result?.loginHints ?? {};
        if (loginHints.hasLoginLink && !loginHints.hasMyCoupang) {
            throw new AuthRequiredError('coupang.com', 'Please log into Coupang in Chrome and retry.');
        }
        const actualProductId = normalizeProductId(result?.currentProductId || productId);
        if (result?.reason === 'PRODUCT_MISMATCH') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass --product-id with the Coupang product number, e.g. --product-id 1234567890
  2. Or pass --url with the canonical product URL, e.g. --url 'https://www.coupang.com/vp/products/1234567890'
  3. Check flag spelling and that shell variables expanding into the flags are non-empty
  4. Prefer --product-id when you have it; URL extraction is stricter about URL format

Example fix

// before
await runCli('coupang add-to-cart'); // ArgumentError
// after
await runCli('coupang add-to-cart', '--product-id', '1234567890');
Defensive patterns

Strategy: validation

Validate before calling

const productId = process.env.COUPANG_PRODUCT_ID;
const url = process.env.COUPANG_URL;
if (!productId && !url) throw new Error('Set COUPANG_PRODUCT_ID or COUPANG_URL before invoking coupang add-to-cart');

Type guard

function hasCoupangTarget(args) {
  return Boolean(args && (args['product-id'] || args.url));
}

Try / catch

try {
  await runCli('coupang add-to-cart', ...args);
} catch (e) {
  if (/Either --product-id or --url is required/.test(e.message)) {
    console.error('Usage: coupang add-to-cart --product-id <id> | --url <productUrl>');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the coupang add-to-cart command's func with kwargs where both kwargs['product-id'] and kwargs.url are undefined/empty — i.e. invoking the CLI with neither flag (or with empty-string values), e.g. `coupang add-to-cart` with no arguments.

Common situations: Forgetting flags in a scripted invocation, passing flags with misspelled names (e.g. --productid or --product_id instead of --product-id), or environment variable interpolation producing empty strings for both options.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3616cd3cf94c5757. Report an issue: GitHub.