{"record":{"id":"f8750f69b988ac0e","repo":"jackwener/OpenCLI","slug":"label-f8750f","errorCode":null,"errorMessage":"${label}","messagePattern":"\\$\\{label\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/instagram/profile.js","lineNumber":19,"sourceCode":"import { cli } from '@jackwener/opencli/registry';\ncli({\n    site: 'instagram',\n    name: 'profile',\n    access: 'read',\n    description: 'Get Instagram user profile info',\n    domain: 'www.instagram.com',\n    args: [\n        { name: 'username', required: true, positional: true, help: 'Instagram username' },\n    ],\n    columns: ['username', 'name', 'followers', 'following', 'posts', 'verified', 'bio'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const username = \\${{ args.username | json }};\n  const opts = { credentials: 'include', headers: { 'X-IG-App-ID': '936619743392459' } };\n  function normalizeInstagramUserId(value, label) {\n    const id = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');\n    if (!/^\\\\d+$/.test(id)) throw new Error(label);\n    return id;\n  }\n  async function readInstagramJson(response, label) {\n    try {\n      return await response.json();\n    } catch {\n      throw new Error(label + ' returned invalid JSON');\n    }\n  }\n  function throwInstagramHttpError(response, label) {\n    if (response.status === 404) throw new Error('User not found: ' + username);\n    if (response.status === 401 || response.status === 403) {\n      throw new Error('HTTP ' + response.status + ' - make sure you are logged in to Instagram');\n    }\n    throw new Error(label + ' failed: HTTP ' + response.status);\n  }\n  function mapProfileUser(u, countFields) {\n    if (!u || typeof u !== 'object' || typeof u.username !== 'string' || !u.username.trim()) {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/profile.js#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify you are logged in to Instagram in the CLI browser session (credentials: 'include' needs a valid cookie)","Confirm the username exists and is spelled correctly","Check the actual feed-by-username response shape; if Instagram changed it, update the extraction (?.user?.pk)","Retry later — empty payloads for restricted accounts are sometimes transient"],"exampleFix":"// before: pk extracted without inspection\nconst pk = normalizeInstagramUserId((data)?.user?.pk, label);\n// after: log/inspect the payload to see what actually came back\nconsole.log(JSON.stringify(data).slice(0, 500));\nconst pk = normalizeInstagramUserId(data?.user?.pk, label);","handlingStrategy":"validation","validationCode":"// Validate the handle shape before invoking the profile command\nif (!/^[A-Za-z0-9._]{1,30}$/.test(username)) {\n  throw new Error('Invalid Instagram handle: ' + username);\n}","typeGuard":"function hasNumericPk(user) {\n  return user !== null && typeof user === 'object' &&\n    (typeof user.pk === 'number' || (typeof user.pk === 'string' && /^\\d+$/.test(user.pk)));\n}","tryCatchPattern":"try {\n  const profile = await instagramProfile(username);\n} catch (e) {\n  if (/no valid profile owner/.test(e.message)) {\n    // feed-by-username returned no pk: retry after confirming login, or treat as restricted account\n    return null;\n  }\n  throw e;\n}","preventionTips":["Ensure the session is logged in before querying business/creator accounts that hit the fallback path","Confirm the target account has a resolvable feed (private/restricted accounts may return empty payloads)","Log the raw feed-by-username JSON when debugging so schema changes are caught early"],"tags":["instagram","validation","profile-api","payload-shape"],"backgroundTag":"invalid-response-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}