Instagram API Tutorial

How to Scrape Instagram Profile Data

Scrape public Instagram profile data including bio, stats, and recent posts. This guide walks you through the entire process, with copy-paste code examples in Node.js, JavaScript, Python, PHP, Ruby, Java, C#, Go, Rust, TypeScript, Swift, Kotlin, R and cURL.

Overview

What You'll Learn

  • Setting up your environment
  • Installing the required HTTP client
  • Authenticating with SociaVault API
  • Making requests to Instagram
  • Handling responses and errors

What You'll Get

  • Access to profile data
  • JSON formatted responses
  • Real-time data access
  • Scalable solution
  • Error handling patterns

Prerequisites

1. API Key

First, you'll need a SociaVault API key to authenticate your requests.

2. Development Environment

Make sure you have the following ready:

  • Your preferred language installed (Python, Node.js, etc.)
  • A code editor (VS Code, Sublime, etc.)
  • Command line interface access

Implementation

Pick your language below — the install command and full code example update accordingly.

Step 1: Install the HTTP client (Node.js)

We'll use axios to make HTTP requests in Node.js.

bash
npm install axios

Step 2: Make the request (Node.js)

Here's the full Node.js example. Replace YOUR_API_KEY with your actual API key.

nodejs
import axios from 'axios';

const API_KEY = 'YOUR_API_KEY';

async function scrape() {
  try {
    const response = await axios.get(`https://api.sociavault.com/instagram/profile?handle=instagram`, {
      headers: {
        'x-api-key': API_KEY,
        'Content-Type': 'application/json'
      }
    });

    console.log('Response:', response.data);
    return response.data;
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
}

// Usage
scrape();

Testing Your Code

API Parameters

ParameterTypeRequiredDescription
handlestringYesExample: instagram

Expected Response

You should receive a structured JSON response containing the profile data.

json
{
  "success": true,
  "data": {
    "user": {
      "biography": "Scraping the web",
      "bio_links": [
        {
          "title": "Social Media APIs",
          "lynx_url": "https://l.instagram.com/?u=https%3A%2F%2Fsociavault.com%2F&e=AT32oytzGxbTPpiHKaOPg3a8nbqySwACFQBVT0tShRMXoo7PirvOqfORNEZntjWlzshBsugLij6QzvWi-lCCezNsWqPZ5Hqn",
          "url": "https://sociavault.com",
          "link_type": "external"
        }
      ],
      "biography_with_entities": {
        "raw_text": "Scraping the web"
      },
      "blocked_by_viewer": false,
      "country_block": false,
      "eimu_id": "114948679895803",
      "external_url": "https://sociavault.com/",
      "external_url_linkshimmed": "https://l.instagram.com/?u=https%3A%2F%2Fsociavault.com%2F&e=AT2QOyCnbcuRIU7Z3_mHRtDkxiraSpS0fZqZKz2lP2lftK23jiEso9nNpoROavW_OaKmTb-9giBBrQ3hKFIgQGwmsmq--jB9",
      "edge_followed_by": {
        "count": 25116
      },
      "fbid": "17841402777077586",
      "followed_by_viewer": false,
      "edge_follow": {
        "count": 101
      },
      "follows_viewer": false,
      "full_name": "Adrian Horning",
      "has_ar_effects": false,
      "has_clips": true,
      "has_guides": false,
      "has_channel": false,
      "has_blocked_viewer": false,
      "highlight_reel_count": 0,
      "has_onboarded_to_text_post_app": true,
      "has_requested_viewer": false,
      "hide_like_and_view_counts": false,
      "id": "2700692569",
      "is_business_account": true,
      "is_professional_account": true,
      "is_supervision_enabled": false,
      "is_guardian_of_viewer": false,
      "is_supervised_by_viewer": false,
      "is_supervised_user": false,
      "is_embeds_disabled": false,
      "is_joined_recently": false,
      "business_address_json": "{\"city_name\": \"Austin, Texas\", \"city_id\": 106224666074625, \"latitude\": 30.26759, \"longitude\": -97.74299, \"street_address\": null, \"zip_code\": null}",
      "business_contact_method": "UNKNOWN",
      "business_category_name": "None",
      "category_name": "Entrepreneur",
      "is_private": false,
      "is_verified": true,
      "is_verified_by_mv4b": false,
      "is_regulated_c18": false,
      "edge_mutual_followed_by": {
        "count": 0
      },
      "pinned_channels_list_count": 0,
      "profile_pic_url": "https://scontent-iad3-1.cdninstagram.com/v/t51.2885-19/430086429_362220943449758_2621012714660517106_n.jpg?stp=dst-jpg_e0_s150x150_tt6&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=102&_nc_ohc=bQwYevo7DQIQ7kNvgFIVNZE&_nc_gid=fca53e0e047a4c5f93d520676b6366b5&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYAiPpD6ibLR9blNyb59-KNrQjsyYe3o1UkTyjK_fG92dw&oe=6799C629&_nc_sid=8b3546",
      "profile_pic_url_hd": "https://scontent-iad3-1.cdninstagram.com/v/t51.2885-19/430086429_362220943449758_2621012714660517106_n.jpg?stp=dst-jpg_s320x320_tt6&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=102&_nc_ohc=bQwYevo7DQIQ7kNvgFIVNZE&_nc_gid=fca53e0e047a4c5f93d520676b6366b5&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYB5Q4gPMQ1Qm2hPTXH8rEpUEPkDxd0pRuPA6QdBf37jPQ&oe=6799C629&_nc_sid=8b3546",
      "requested_by_viewer": false,
      "should_show_category": false,
      "should_show_public_contacts": true,
      "show_account_transparency_details": true,
      "show_text_post_app_badge": false,
      "remove_message_entrypoint": false,
      "username": "opi",
      "edge_felix_video_timeline": {
        "count": 0,
        "page_info": {
          "has_next_page": false
        }
      },
      "edge_owner_to_timeline_media": {
        "count": 71,
        "page_info": {
          "has_next_page": true,
          "end_cursor": "QVFDdUZKSGhpeXExcGp5SVppc09Pd1lNbDhkSEZfeDhzUlNwaThFTlNZckdmZG40Q2hKSmxuX1FVS3dlbmpqWkVvMTBGUkVvSklVMWktWEx2T1JlRGlFQw=="
        },
        "edges": [
          {
            "node": {
              "__typename": "GraphVideo",
              "id": "3540614075954356349",
              "shortcode": "DEiyb48AeB9",
              "dimensions": {
                "height": 1920,
                "width": 1080
              },
              "display_url": "https://scontent-iad3-2.cdninstagram.com/v/t51.2885-15/472965900_18326364268092570_5931185706033057724_n.jpg?stp=dst-jpg_e35_p1080x1080_sh0.08_tt6&_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=106&_nc_ohc=xKs91h4eoI0Q7kNvgHoonkr&_nc_gid=fca53e0e047a4c5f93d520676b6366b5&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYB7Jx1JWWnRAzhY4FuHx8q2tnLUVKiIBtPtUJUcjtNJkw&oe=6799BC5B&_nc_sid=8b3546",
              "sharing_friction_info": {
                "should_have_sharing_friction": false
              },
              "media_preview": "ABgqVIyQDwAemTj/AD0p5iOM5X8x3qO2k8k9WK+mTx3GOQevXnkVdScOeMn8Xz+Hz1OgymYGzzjHfkHqcf1op7TGXJXO1RwCT9eck9+ntRQBUcYFPtCCy4Y5BOfp/Ws2e73javA7mhZyi8Hk9Mds8Giw0zZiwRkdCT/OiqUN6oAQ8epH4UVLTC5jU8dKZThWhIoNFNooEf/Z",
              "owner": {
                "id": "2700692569",
                "username": "opi"
              },
              "is_video": true,
              "has_upcoming_event": false,
              "has_audio": true,
              "tracking_token": "eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjp0cnVlLCJ1dWlkIjoiZmNhNTNlMGUwNDdhNGM1ZjkzZDUyMDY3NmI2MzY2YjUzNTQwNjE0MDc1OTU0MzU2MzQ5In0sInNpZ25hdHVyZSI6IiJ9",
              "video_url": "https://scontent-iad3-1.cdninstagram.com/o1/v/t16/f2/m86/AQNnK3RhLzpoAq5frHQ4tr0ukvsmz9S1vMh3hrsKqknkqn_5rSMJJ-G4d3m5qQeXaiijzhoXcTJOsWeicR9U11hqAe2aiGLrVgnsq7w.mp4?stp=dst-mp4&efg=eyJxZV9ncm91cHMiOiJbXCJpZ193ZWJfZGVsaXZlcnlfdnRzX290ZlwiXSIsInZlbmNvZGVfdGFnIjoidnRzX3ZvZF91cmxnZW4uY2xpcHMuYzIuNzIwLmJhc2VsaW5lIn0&_nc_cat=104&vs=1270788217346509_2913271887&_nc_vs=HBksFQIYUmlnX3hwdl9yZWVsc19wZXJtYW5lbnRfc3JfcHJvZC8xNTQzRTMyRUZFQTAwNDU0NUNFNTkwNThEQzJDM0U4NF92aWRlb19kYXNoaW5pdC5tcDQVAALIAQAVAhg6cGFzc3Rocm91Z2hfZXZlcnN0b3JlL0dGWTFCaHowdGl1RTIyd0ZBQWVEemNJUFpBQlVicV9FQUFBRhUCAsgBACgAGAAbABUAACaagsiP%2BMePQBUCKAJDMywXQFMt41P3ztkYEmRhc2hfYmFzZWxpbmVfMV92MREAdf4HAA%3D%3D&ccb=9-4&oh=00_AYB4gZagLKrlCAo6WLS3oiRVr_p1fsq008W2I7GZ80uL-g&oe=6795C6C3&_nc_sid=8b3546",
              "video_view_count": 1318,
              "edge_media_to_comment": {
                "count": 12
              },
              "comments_disabled": false,
              "taken_at_timestamp": 1736294201,
              "edge_liked_by": {
                "count": 126
              },
              "edge_media_preview_like": {
                "count": 126
              },
              "thumbnail_src": "https://scontent-iad3-2.cdninstagram.com/v/t51.2885-15/472965900_18326364268092570_5931185706033057724_n.jpg?stp=c0.437.1125.1125a_dst-jpg_e35_s640x640_sh0.08_tt6&_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=106&_nc_ohc=xKs91h4eoI0Q7kNvgHoonkr&_nc_gid=fca53e0e047a4c5f93d520676b6366b5&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYDJ48OhYyfP3khEvTSJi109b0RuewgHJS4Oo3BPxdWlgA&oe=6799BC5B&_nc_sid=8b3546",
              "thumbnail_resources": [
                {
                  "src": "https://scontent-iad3-2.cdninstagram.com/v/t51.2885-15/472965900_18326364268092570_5931185706033057724_n.jpg?stp=c0.437.1125.1125a_dst-jpg_e15_s150x150_tt6&efg=eyJ2ZW5jb2RlX3RhZyI6ImltYWdlX3VybGdlbi4xMTI1eDIwMDAuc2RyLmY3NTc2MS5kZWZhdWx0X2NvdmVyX2ZyYW1lIn0&_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=106&_nc_ohc=xKs91h4eoI0Q7kNvgHoonkr&_nc_gid=fca53e0e047a4c5f93d520676b6366b5&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYAmEArV6dtea6W4qgKqo_R_YwsnASoiDvNamqdwPEg79w&oe=6799BC5B&_nc_sid=8b3546",
                  "config_width": 150,
                  "config_height": 150
                }
              ],
              "viewer_can_reshare": true,
              "like_and_view_counts_disabled": false,
              "product_type": "clips",
              "clips_music_attribution_info": {
                "artist_name": "opi",
                "song_name": "Original audio",
                "uses_original_audio": true,
                "should_mute_audio": false,
                "should_mute_audio_reason": "",
                "audio_id": "577003721993612"
              }
            }
          }
        ]
      },
      "edge_saved_media": {
        "count": 0,
        "page_info": {
          "has_next_page": false
        }
      },
      "edge_media_collections": {
        "count": 0,
        "page_info": {
          "has_next_page": false
        }
      },
      "edge_related_profiles": {
        "edges": [
          {
            "node": {
              "id": "66873381803",
              "full_name": "ally",
              "is_private": false,
              "is_verified": false,
              "profile_pic_url": "https://scontent-iad3-2.cdninstagram.com/v/t51.2885-19/465249338_1115706923297633_2956285260068952346_n.jpg?stp=dst-jpg_e0_s150x150_tt6&_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=105&_nc_ohc=VDjmLlINuRcQ7kNvgGN3eSS&_nc_gid=fca53e0e047a4c5f93d520676b6366b5&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYBboj0XGYiNsfaQBDRV0gzqn3m8L8PdwFh18sjOW4XOFg&oe=6799E5F1&_nc_sid=8b3546",
              "username": "itsallykrinsky"
            }
          }
        ]
      }
    }
  },
  "status": "ok"
}

Best Practices

Error Handling

Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.

Caching

Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.

Security

Never expose your API key in client-side code. Use environment variables and secure key management practices.

Troubleshooting

401

Unauthorized

Check your API key is correct and properly formatted in the x-api-key header.

402

Payment Required

You ran out of credits and need to buy more.

404

Not Found

The resource (user, video, etc.) might not exist or be private.

429

Too Many Requests

You have exceeded your rate limit. Slow down your requests.

Frequently Asked Questions

How much does it cost to scrape Instagram?

SociaVault offers 50 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.

Is it legal to scrape Instagram data?

Scraping publicly available data is generally considered legal. We only collect public data that is accessible without logging in.

Which programming languages can I use to scrape Instagram?

Any language that can make an HTTP request. This tutorial includes ready-to-use examples in Node.js, JavaScript, Python, PHP, Ruby, Java, C#, Go, Rust, TypeScript, Swift, Kotlin, R, cURL.

What data format does the API return?

All API responses are returned in JSON format, making it easy to integrate with any programming language or application.

Related Tutorials

Ready to Start Scraping?

Get started with 50 free API calls. No credit card required. Stop worrying about proxies and captchas.