jackwener/OpenCLI · error · ArgumentError

--subject must be 200 characters or fewer

Error message

--subject must be 200 characters or fewer

What it means

buildCreateMessagePayload enforces a maximum subject length of 200 characters (after normalization). Subjects exceeding that limit would be rejected by the Sales Navigator API, so the library fails fast with ArgumentError.

Source

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

  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 = [];
  const visit = (value) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Shorten the subject to 200 characters or fewer.
  2. Collapse excessive whitespace before sending (the library normalizes nbsp, so pre-trim your template).
  3. Truncate programmatically: subject.slice(0, 200) with ellipsis if acceptable.

Example fix

// before
const subject = veryLongTemplate;
// after
const subject = veryLongTemplate.length > 200 ? veryLongTemplate.slice(0, 197) + '...' : veryLongTemplate;
Defensive patterns

Strategy: validation

Validate before calling

if ([...String(subject).replace(/[\u00a0\u202f]/g,' ')].length > 200) subject = subject.slice(0, 200);

Try / catch

try { await sendMessage({ subject, body }); } catch (e) { if (/subject must be 200 characters or fewer/.test(e.message)) { subject = subject.slice(0, 200); /* retry */ } else throw e; }

Prevention

When it happens

Trigger: cleanSubject.length > 200 — a subject longer than 200 characters after whitespace normalization.

Common situations: Auto-generated or templated subjects (long job titles, merged fields) exceeding the cap; pasted rich text with extra non-breaking spaces inflating length.

Related errors


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