jackwener/OpenCLI · error · ArgumentError

--body is required

Error message

--body is required

What it means

buildCreateMessagePayload requires a non-empty body (trimmed); an empty message body is rejected before the API call with an ArgumentError.

Source

Thrown at clis/linkedin/salesnav-message.js:93

  if (!recipient?.profileId || !recipient?.authType || !recipient?.authToken) return '';
  const key = `(profileId:${recipient.profileId},authType:${recipient.authType},authToken:${recipient.authToken})`;
  return `https://www.linkedin.com/sales-api/salesApiProfiles/${key}?decoration=${encodeRestliDecoration(PROFILE_DECO)}`;
}

function randomTrackingId() {
  const bytes = new Uint8Array(8);
  if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(bytes);
  else for (let i = 0; i < bytes.length; i += 1) bytes[i] = Math.floor(Math.random() * 256);
  return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
}

function buildCreateMessagePayload({ recipientUrn, subject, body, trackingId = randomTrackingId(), copyToCrm = false }) {
  const cleanRecipient = normalizeWhitespace(recipientUrn);
  if (!parseSalesProfileUrn(cleanRecipient)) throw new ArgumentError('--recipient must resolve to a Sales Navigator lead urn');
  const cleanSubject = normalizeWhitespace(subject);
  const cleanBody = String(body ?? '').trim();
  if (!cleanSubject) throw new ArgumentError('--subject is required');
  if (!cleanBody) throw new ArgumentError('--body is required');
  if (cleanSubject.length > 200) throw new ArgumentError('--subject must be 200 characters or fewer');
  if (cleanBody.length > 1900) throw new ArgumentError('--body must be 1900 characters or fewer');
  return {
    createMessageRequest: {
      recipients: [cleanRecipient],
      subject: cleanSubject,
      body: cleanBody,
      copyToCrm: Boolean(copyToCrm),
      trackingId,
    },
  };
}

function extractRemainingCredits(json) {
  const elements = Array.isArray(json?.elements) ? json.elements : [];
  const inmailGrant = elements.find((el) => el?.type === 'LSS_INMAIL' && Number.isInteger(el.value));
  if (inmailGrant) return inmailGrant.value;
  const candidates = [];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide --body "Your message text".
  2. Verify shell quoting so multiline bodies are passed intact.
  3. Ensure the body has at least one non-whitespace character.

Example fix

// before
linkedin salesnav-message --recipient "..." --subject "Hi"
// after
linkedin salesnav-message --recipient "..." --subject "Hi" --body "Let's connect."
Defensive patterns

Strategy: validation

Validate before calling

if (!args.body || !String(args.body).trim()) throw new Error('pass a non-empty --body');

Type guard

function hasBody(a) { return typeof a.body === 'string' && a.body.trim().length > 0; }

Try / catch

try { await sendMessage(args); } catch (e) { if (/--body is required/.test(e.message)) { console.error('Body text missing; supply --body'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: --body is omitted, empty, or contains only whitespace.

Common situations: Omitting --body on the CLI; heredoc/quoting mistakes yielding an empty string; programmatic payload building passing undefined body.

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/aeedf08046c73cda. Report an issue: GitHub.