Skip to content

fix: request saved posts through the Instagram web host - #34

Merged
gitnasr merged 1 commit into
masterfrom
fix/instagram-web-request
Nov 2, 2026
Merged

gitnasr merged 1 commit into
masterfrom
fix/instagram-web-request

Conversation

@gitnasr

@gitnasr gitnasr commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Scrapes stop with Instagram API returned status: fail, and the reason is lost. This keeps the reason and moves the request to the host and headers other current projects use. Those projects' code is the basis for the switch; the actual cause is still unconfirmed.

 requestSavedPostsPage / fetchLoggedInUser
-  GET i.instagram.com/api/v1/...
-    User-Agent: Instagram 407 Android   (default)
-    Cookie
+  GET www.instagram.com/api/v1/...
+    User-Agent: desktop Chrome          (default)
+    Cookie
+    X-IG-App-ID, X-ASBD-ID, X-IG-WWW-Claim, X-Requested-With, Referer, Sec-Fetch-*
+    X-CSRFToken                         (when the cookie has csrftoken)
 on(2xx response)
+  if body is not JSON
+    throw auth "session has likely expired"
   if status != "ok"
-    throw "returned status: fail"
+    throw "returned status: fail (<Instagram's message>)", with body kept on the run
-  classify login_required, checkpoint_required as auth
+  classify login_required, checkpoint_required, challenge_required as auth

Also drops the include_feed_only query parameter, which none of the web examples checked send, and updates the UI placeholders that mentioned the Android default.

Evidence

  • Before: production log, with no reason from Instagram:
    "kind":"fatal","status":"failed","message":"Instagram API returned status: fail"
    
    After: npm run test:instagram (new, Instagram stubbed) prints instagram-api ok. It asserts:
    {status:"fail", message:"something new"} -> errorMsg "...status: fail (something new)", errorBody has the JSON, fatal, no retry
    message "challenge_required"             -> auth
    HTML body                                -> auth, errorBody capped at 2000 chars
    request                                  -> www host, X-IG-App-ID, X-CSRFToken from cookie, custom user agent respected
    

Not verified against live Instagram. No before/after from a real scrape yet. Test this on a deployment before merging, because merging publishes a release.

  • npm run lint passes with 0 errors
  • npx tsc --noEmit passes with 0 errors
  • npm run build succeeds
  • Tested manually in development / Docker environment

Release note

Release-Note: Scrapes now use Instagram's web API, and failed runs show Instagram's actual error. If a profile has a custom Android user agent, clear it or replace it with your browser's.

  • Breaking change

Type: Bug fix

Merge Danger

Door: two-way

No schema or data changes. Revert restores the old request.

Blast Radius: scraping

Every scrape and avatar lookup changes request shape, on accounts Instagram may already be restricting. Profiles with a saved custom user agent keep it, so a saved Android string stays mismatched with the new host until cleared.

Docs: gitnasr/instagram-saved-posts-landing, branch docs/instagram-challenge-errors.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Updated Instagram requests to use web-client settings and browser-style identification.
    • Improved error reporting for authentication challenges and failed responses, including limited response details.
  • Bug Fixes
    • Updated the displayed default User-Agent to match the desktop Chrome setting.

Scrapes were stopping with "Instagram API returned status: fail" and the
reason was lost, because a failure reported with a 2xx has no axios error
to read the body from.

Keep Instagram's reason in the error message and its response body on the
run, and classify challenge_required as auth.

Call www.instagram.com with the web client's headers and a desktop Chrome
default user agent instead of i.instagram.com with an Android one, since
the cookie comes from a browser. A non-JSON response now reports as an
expired session. Not yet verified against live Instagram.

Profiles with a saved custom user agent keep using it. If it is the old
Android string, clear it or replace it with your browser's.

Release-Note: Scrapes now use Instagram's web API, and failed runs show Instagram's actual error. If a profile has a custom Android user agent, clear it or replace it with your browser's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The change switches Instagram saved-post and logged-in-user requests to web-client URLs and headers, updates the default User-Agent, and retains response bodies in scrape errors. It also updates User-Agent placeholders and adds a self-check script for request configuration and error handling.

Changes: Instagram Web API

Layer / File(s) Summary
Web-client request configuration and API behavior
src/lib/constants.ts, src/types/instagram.ts, src/lib/instagram-api.ts, src/app/(dashboard)/settings/page.tsx, src/components/onboarding/onboarding-wizard.tsx, src/components/profiles/profile-form-dialog.tsx
The API uses Instagram web-client constants and headers for saved-post and logged-in-user requests. It recognizes challenge responses, retains truncated response bodies in scrape errors, and updates the default User-Agent. The UI placeholders now describe the desktop Chrome default.
Scrape error body extraction
src/lib/scraper/errors.ts
extractErrorInfo returns a truthy body from ScrapeRequestError as errorBody.
API self-check coverage
package.json, scripts/test-instagram-api.ts
The test:instagram script runs checks for request configuration, error classification and details, body truncation, and logged-in-user lookup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: Low · up to 5ce91

The changes are mergeable with bounded follow-up: preserve retry handling for HTML rate-limit messages and cap stored error messages. These are narrow issues; no broader request incompatibility was established.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@gitnasr
gitnasr merged commit 1e68b7b into master Nov 2, 2026
3 checks passed
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🧪 Beta Container Ready for Testing

A preview beta version has been built for this Pull Request:

  • Beta Version: 1.5.2-beta.34
  • Docker Tag: ghcr.io/gitnasr/instagram-saved-posts:beta-pr-34
  • Rolling Beta Tag: ghcr.io/gitnasr/instagram-saved-posts:beta
# Test this PR build locally:
docker pull ghcr.io/gitnasr/instagram-saved-posts:beta-pr-34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant