Skip to content

NYSCAttach (pronounced Nisk-attach): The NY Courts eNotify Attachment Downloader

License

Notifications You must be signed in to change notification settings

RyokoAsakura/NYSCAttach

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

NYSCAttach

NYSCAttach (pronounced Nisk-attach): The NY Courts eNotify Attachment Downloader


A Python script to download all PDF attachments from a NY Courts eNotify inbox, while working with Cloudflare protections and the iapps viewer token flow.

This project uses Playwright to attach to a real, human-driven Chrome session via the Chrome DevTools Protocol (CDP). It does not attempt to bypass Cloudflare. Instead, it leverages the already-authenticated browser session to retrieve attachments safely and reliably.


Problem This Solves

The NY Courts eNotify system:

  • Is protected by Cloudflare
  • Requires a valid login session
  • Serves attachments via a redirect to:
    https://iapps.courts.state.ny.us/vscms_public/viewer?action=inline&token=...

Common automation approaches fail because:

  • Direct HTTP requests receive 403 "Just a moment..." responses from Cloudflare
  • The Chrome PDF viewer returns a small HTML wrapper instead of the actual PDF bytes
  • The iapps viewer URL requires a valid browser session and token

This script works by:

  1. Attaching to a real Chrome instance (already logged in)
  2. Calling the internal /api/inbox endpoint via in-page fetch
  3. Navigating to each attachment URL to capture the 302 redirect
  4. Extracting the Location header (iapps viewer token URL)
  5. Downloading the PDF using the browser context
  6. Verifying the file starts with %PDF- before saving

Requirements

  • Python 3.9+
  • Google Chrome
  • Playwright (Python)

Install dependencies:

pip install playwright
python -m playwright install chromium

Usage

Step 1: Start Chrome with Remote Debugging

Start Chrome with a persistent profile and remote debugging enabled:

google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/nycourts-profile

Important: - Do not close this browser while the script is running. - Use the same profile directory every time.


Step 2: Log In Manually

In the opened Chrome window:

Leave the browser open on the Inbox.


Step 3: Run the Script

python downloader_redirect_pdf.py

The script will:

  • Iterate through inbox pages
  • Open each message with attachments
  • Download all PDFs into:
    ./downloads/<message_guid>/

It maintains a _download_log.json file to avoid re-downloading files.


How It Works

Cloudflare Compatibility

Cloudflare blocks direct API or HTTP client access.

This script avoids that by:

  • Using connect_over_cdp() to attach to the real Chrome session
  • Executing /api/inbox calls via window.fetch() inside the page
  • Performing attachment navigation in a real browser tab

No headless automation is used for login.


Attachment Flow

For each attachment:

  1. Navigate to: /Inbox/<guid>/Attachment/<id>

  2. Capture the 302 redirect response.

  3. Extract: https://iapps.courts.state.ny.us/vscms_public/viewer?...token=...

  4. Download that URL.

  5. Verify the first bytes are: %PDF-

  6. Save as a .pdf file.

This avoids saving the Chrome PDF viewer wrapper (which is ~536 bytes of HTML).


Output Structure

downloads/
  <message_guid>/
    001_<attachment_name>.pdf
    002_<attachment_name>.pdf
  _download_log.json

The log file stores:

  • Attachment ID
  • iapps token URL
  • Timestamp
  • File size

Notes

  • The script does not attempt to bypass Cloudflare.
  • It requires an already-authenticated human session.
  • It intentionally adds small delays between downloads to avoid flooding requests.
  • If a file does not begin with %PDF-, it will not be saved.

Known Limitations

  • Requires a running Chrome instance.
  • Token URLs are short-lived and must be used immediately.
  • Large inboxes may take significant time to process.

Legal and Ethical Considerations

This tool is intended only for downloading documents from your own authorized NY Courts eNotify account.

You are responsible for complying with all applicable laws, court rules, and terms of service.


License

GNUGPLv3

About

NYSCAttach (pronounced Nisk-attach): The NY Courts eNotify Attachment Downloader

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages