Instagram API Server

This Cloudflare Worker connects to Instagram accounts and serves Instagram media via API endpoints.

Get Started

Login with Instagram

Authentication

Instagram OAuth Login

Direct Instagram OAuth authentication for accessing your Instagram account.

Requirements: Instagram Business or Creator account

API Endpoints

GET /images/{userId or username}

Get user's Instagram media (cached for 1 hour)

You can use either the user ID or Instagram username (with or without @).

Parameters:

Caching: Responses are cached for 1 hour. Check the X-Cache header (HIT/MISS).

GET /images/123456789?limit=10&after=cursor_value  # By user ID
GET /images/johndoe?limit=10  # By username
GET /images/@johndoe  # With @ symbol
GET /images/123456789?bust=true  # Force fresh data

GET /image/{userId or username}/{mediaId}

Get specific media item details

You can use either the user ID or Instagram username.

GET /image/123456789/media_id_here  # By user ID
GET /image/johndoe/media_id_here  # By username

POST /cache/bust/{userId}

Clear cached media for a user

Call this endpoint when new media is posted to Instagram to refresh the cache.

POST /cache/bust/123456789

GET/POST /webhook

Instagram webhook endpoint (automatic cache busting)

GET: Webhook verification endpoint

POST: Receives webhook events from Instagram

Configure this in your Instagram app settings to automatically bust cache when new media is posted.

Verify Token: instagram_webhook_verify_2025

GET /health

Health check endpoint

GET /health

Requirements

Setup Instructions

  1. Create a Meta app at Meta Developers
  2. Add "Instagram Basic Display" product to your app
  3. Configure OAuth redirect URI in the app settings
  4. Add your Instagram account as a test user
  5. Update wrangler.toml with your app credentials
  6. Deploy the worker

Webhook Setup (Optional)

  1. Go to your Meta app → Products → Webhooks
  2. Subscribe to Instagram webhooks
  3. Callback URL: https://instagram.larka.tech/webhook
  4. Verify Token: instagram_webhook_verify_2025
  5. Subscribe to media events
  6. When you post new media on Instagram, the cache will automatically refresh!