jackwener/OpenCLI · error · Error

${label}

Error message

${label}

What it means

normalizeInstagramUserId inside the profile.js in-page evaluate script validates a resolved user id (pk). If the value is neither a number nor a digit-only string, it throws Error(label) where label is a descriptive message like 'Instagram feed returned no valid profile owner for: <username>'. This guards the feed-by-username fallback used for business/professional accounts.

Source

Thrown at clis/instagram/profile.js:19

import { cli } from '@jackwener/opencli/registry';
cli({
    site: 'instagram',
    name: 'profile',
    access: 'read',
    description: 'Get Instagram user profile info',
    domain: 'www.instagram.com',
    args: [
        { name: 'username', required: true, positional: true, help: 'Instagram username' },
    ],
    columns: ['username', 'name', 'followers', 'following', 'posts', 'verified', 'bio'],
    pipeline: [
        { navigate: 'https://www.instagram.com' },
        { evaluate: `(async () => {
  const username = \${{ args.username | json }};
  const opts = { credentials: 'include', headers: { 'X-IG-App-ID': '936619743392459' } };
  function normalizeInstagramUserId(value, label) {
    const id = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');
    if (!/^\\d+$/.test(id)) throw new Error(label);
    return id;
  }
  async function readInstagramJson(response, label) {
    try {
      return await response.json();
    } catch {
      throw new Error(label + ' returned invalid JSON');
    }
  }
  function throwInstagramHttpError(response, label) {
    if (response.status === 404) throw new Error('User not found: ' + username);
    if (response.status === 401 || response.status === 403) {
      throw new Error('HTTP ' + response.status + ' - make sure you are logged in to Instagram');
    }
    throw new Error(label + ' failed: HTTP ' + response.status);
  }
  function mapProfileUser(u, countFields) {
    if (!u || typeof u !== 'object' || typeof u.username !== 'string' || !u.username.trim()) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify you are logged in to Instagram in the CLI browser session (credentials: 'include' needs a valid cookie)
  2. Confirm the username exists and is spelled correctly
  3. Check the actual feed-by-username response shape; if Instagram changed it, update the extraction (?.user?.pk)
  4. Retry later — empty payloads for restricted accounts are sometimes transient

Example fix

// before: pk extracted without inspection
const pk = normalizeInstagramUserId((data)?.user?.pk, label);
// after: log/inspect the payload to see what actually came back
console.log(JSON.stringify(data).slice(0, 500));
const pk = normalizeInstagramUserId(data?.user?.pk, label);
Defensive patterns

Strategy: validation

Validate before calling

// Validate the handle shape before invoking the profile command
if (!/^[A-Za-z0-9._]{1,30}$/.test(username)) {
  throw new Error('Invalid Instagram handle: ' + username);
}

Type guard

function hasNumericPk(user) {
  return user !== null && typeof user === 'object' &&
    (typeof user.pk === 'number' || (typeof user.pk === 'string' && /^\d+$/.test(user.pk)));
}

Try / catch

try {
  const profile = await instagramProfile(username);
} catch (e) {
  if (/no valid profile owner/.test(e.message)) {
    // feed-by-username returned no pk: retry after confirming login, or treat as restricted account
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: clis/instagram/profile <username> hits the fallback path (web_profile_info returned 400, typical for business accounts), and the feed-by-username response has no user.pk (or a non-numeric pk), e.g. response shape changed or empty items list.

Common situations: Business/creator account with no visible feed items; Instagram API response schema change removing user.pk; restricted/blocked account returning an empty payload; not logged in so the feed endpoint returns a limited body.

Related errors


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