jackwener/OpenCLI · error · ArgumentError

--subject is required

Error message

--subject is required

What it means

buildCreateMessagePayload requires a non-empty subject after whitespace normalization; an empty subject cannot be sent via the Sales Navigator create-message API, so it throws ArgumentError.

Source

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

function profileApiUrl(recipient) {
  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;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide --subject "Your subject line".
  2. Check quoting/escaping in your shell so the value isn't lost.
  3. Trim/pad the subject to at least one non-whitespace character before calling.

Example fix

// before
linkedin salesnav-message --recipient "..." --body "hi"
// after
linkedin salesnav-message --recipient "..." --subject "Quick intro" --body "hi"
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try { await sendMessage(args); } catch (e) { if (/--subject is required/.test(e.message)) { args.subject = '(no subject)'; /* retry with default */ } else throw e; }

Prevention

When it happens

Trigger: --subject is omitted, empty string, or only whitespace/non-breaking spaces (normalizeWhitespace yields '').

Common situations: Forgetting the --subject flag; shell quoting issues that drop the value; pasting a subject of only spaces; programmatic calls passing undefined in the subject field.

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