Back to Blog
General

Instagram Posts Scraper API: Extract All Posts from Any Profile

February 2, 2026
5 min read
S
By SociaVault Team
instagramposts scraperapicontent analysis

Instagram Posts Scraper API: Extract Post Data at Scale

Need to analyze Instagram content? This guide shows you how to extract posts, captions, engagement metrics, and media from any public Instagram profile.

What Post Data Can You Extract?

FieldDescription
pk / idUnique post identifier
codeShortcode for URL (instagram.com/p/{code})
caption.textFull post caption text
like_countNumber of likes
comment_countNumber of comments
play_countView count (video posts)
media_type1 = Photo, 2 = Video, 8 = Carousel
video_versionsVideo URLs at various qualities
image_versions2Image URLs at various sizes
taken_atUnix timestamp when posted
usertagsTagged users in the post
video_durationVideo length in seconds

Using the Posts Scraper API

const response = await fetch(
  'https://api.sociavault.com/v1/scrape/instagram/posts?handle=opi',
  {
    method: 'GET',
    headers: {
      'x-api-key': 'YOUR_API_KEY'
    }
  }
);

const result = await response.json();
const items = Object.values(result.data.items);

You can also pass trim=true to get a smaller response without embedded media CDN data.

Sample Response

The response contains an items object with numeric keys, each representing a post:

{
  "success": true,
  "data": {
    "success": true,
    "next_max_id": "3822431353875645727_270598518",
    "more_available": true,
    "num_results": 12,
    "user": {
      "pk": "270598518",
      "username": "opi",
      "full_name": "OPI",
      "is_verified": true
    },
    "items": {
      "0": {
        "pk": "3824512658796290411",
        "id": "3824512658796290411_270598518",
        "code": "DUTZgACiaFr",
        "media_type": 2,
        "caption": {
          "text": "The next generation of icons has arrived. 💅 Our New OPIcons Collection...",
          "created_at_utc": 1770137535
        },
        "like_count": 2531,
        "comment_count": 62,
        "play_count": 100404,
        "video_duration": 15,
        "taken_at": 1770137534,
        "image_versions2": {
          "candidates": {
            "0": { "url": "https://scontent...", "width": 640, "height": 1136 }
          }
        },
        "video_versions": {
          "0": { "url": "https://scontent...", "width": 480, "height": 852 }
        },
        "usertags": {
          "in": {
            "0": { "user": { "username": "thisis_jelly", "full_name": "Jelly" } }
          }
        }
      }
    }
  },
  "credits_used": 1,
  "endpoint": "instagram/posts"
}

Key fields per item:

  • Post ID: pk or id
  • Shortcode: code (for building instagram.com/p/{code} URLs)
  • Caption: caption.text
  • Likes: like_count
  • Comments: comment_count
  • Views: play_count (video posts)
  • Media type: media_type (1 = photo, 2 = video, 8 = carousel)
  • Video URL: video_versions[0].url
  • Image URL: image_versions2.candidates[0].url
  • Timestamp: taken_at (Unix timestamp)
  • Tagged users: usertags.in[].user.username

Use Cases

Content Performance Analysis

Identify what content performs best:

async function getPosts(handle) {
  const res = await fetch(
    `https://api.sociavault.com/v1/scrape/instagram/posts?handle=${handle}`,
    { headers: { 'x-api-key': 'YOUR_API_KEY' } }
  );
  return res.json();
}

const result = await getPosts('competitor');
const posts = Object.values(result.data.items);

// Calculate average engagement
const avgLikes = posts.reduce((sum, p) => sum + p.like_count, 0) / posts.length;
const avgComments = posts.reduce((sum, p) => sum + p.comment_count, 0) / posts.length;

// Find top performers
const topPosts = posts
  .sort((a, b) => b.like_count - a.like_count)
  .slice(0, 10);

console.log('Top performing content:', topPosts.map(p => p.code));

Hashtag Analysis

Extract hashtags from post captions:

const hashtagCounts = {};
posts.forEach(post => {
  const hashtags = post.caption?.text?.match(/#\w+/g) || [];
  hashtags.forEach(tag => {
    hashtagCounts[tag] = (hashtagCounts[tag] || 0) + 1;
  });
});

const topHashtags = Object.entries(hashtagCounts)
  .sort((a, b) => b[1] - a[1])
  .slice(0, 20);

Posting Schedule Analysis

Discover optimal posting times:

const postsByHour = {};
posts.forEach(post => {
  const hour = new Date(post.taken_at * 1000).getHours();
  postsByHour[hour] = (postsByHour[hour] || 0) + 1;
});

// Find most common posting hour
const peakHour = Object.entries(postsByHour)
  .sort((a, b) => b[1] - a[1])[0][0];

console.log(`Most common posting hour: ${peakHour}:00`);

Content Type Distribution

Analyze the mix of content types:

const MEDIA_TYPES = { 1: 'photo', 2: 'video', 8: 'carousel' };

const typeCount = posts.reduce((acc, post) => {
  const type = MEDIA_TYPES[post.media_type] || 'unknown';
  acc[type] = (acc[type] || 0) + 1;
  return acc;
}, {});

console.log('Content mix:', typeCount);
// { photo: 3, video: 7, carousel: 2 }

Pagination for All Posts

Get a profile's complete post history using next_max_id:

async function getAllPosts(handle) {
  let allPosts = [];
  let nextMaxId = null;
  
  do {
    const url = new URL('https://api.sociavault.com/v1/scrape/instagram/posts');
    url.searchParams.set('handle', handle);
    if (nextMaxId) url.searchParams.set('next_max_id', nextMaxId);

    const response = await fetch(url, {
      headers: { 'x-api-key': 'YOUR_API_KEY' }
    });
    
    const result = await response.json();
    const items = Object.values(result.data.items);
    allPosts = [...allPosts, ...items];
    nextMaxId = result.data.more_available ? result.data.next_max_id : null;
    
  } while (nextMaxId);
  
  return allPosts;
}

Frequently Asked Questions

How many posts can I retrieve per request?

Each request returns up to 12 posts by default. Use pagination to get more posts.

Can I get posts from private accounts?

No, only public profiles are accessible. Private accounts restrict content to approved followers.

Do I get the actual image/video files?

The API returns URLs to media files. You can download these URLs if needed for your use case.

How far back can I get posts?

You can access a profile's entire public post history, going back to their first post.

Are Instagram Stories included?

No, Stories are ephemeral and not included in posts. Use the Highlights endpoint for saved story content.

Get Started

Create your account and start extracting Instagram posts.

API documentation: /docs/api-reference/instagram/posts

Found this helpful?

Share it with others who might benefit

Ready to Try SociaVault?

Start extracting social media data with our powerful API. No credit card required.