Instagram

The Social Media Scraping API allows you to scrape information from Instagram.

The API uses GraphQL targets which return data in JSON.

📘

While the targets in this page use GraphQL under the hood, they are interfaced with via REST.

The following GraphQL targets are available:

Instagram GraphQL User Posts

Returns information about a specific Instagram user.

ParameterTypeRequiredDescriptionExample
targetstringtargetinstagram_graphql_user_posts
querystringquery or user_idInstagram user profile namenba
user_idstringquery or queryUnique Instagram user id56989304580
cursorstringnext page string (end_cursor value in response)QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA==

Using query vs user_id

The easiest way to use the target is to provide a username as a query:

{
    "target": "instagram_graphql_user_posts",
    "query": "tasty"
}

However, due to Instagram's limitations, using just the query may not work on some usernames. As an escape hatch, you can also provide a user_id to the request.

In order to get the user_id for an account, eg tasty (manual steps):

  1. Navigate to https://www.instagram.com/tasty
  2. Open developer tools and do a global search for "id" in the html. A <script> tag will be highlighted.
  3. Paste the <script> tag into a code editor and search for "id". The id will be nested in one of the profile objects.

This id can then be used in the scraping request:

{
    "target": "instagram_graphql_user_posts",
    "user_id": "56989304580" // user id for account `tasty`
}

Instagram GraphQL profile

Returns information about a specific Instagram user.

ParameterTypeRequiredDescriptionExample
targetstringtargetinstagram_graphql_profile
querystringInstagram profile namenba

Return value JSON:

  • Basic information (name, description, follower count).
  • 12 most recent posts.

Instagram GraphQL post

Returns information from a specific Instagram post.

ParameterTypeRequiredDescriptionExample
targetstringtargetinstagram_graphql_post
urlstringInstagram post URL<https://www.instagram.com/p/ChYHpdAvnob>

Create callback for Instagram post

  POST https://scraper-api.smartproxy.com/v2/task

Payload type: JSON

ParameterTypeRequiredDescriptionExamples
targetstringtargetinstagram_graphql_post
urlurlInstagram post URL<https://www.instagram.com/p/ChYHpdAvnob>
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/task -H "Content-Type: application/json" -d "{\"url\": \"https://www.instagram.com/p/ChYHpdAvnob/\", \"target\": \"instagram_graphql_post\",\"locale\": \"en-us\",\"geo\": \"United States\" }"

Pagination for Posts & Hashtags

Pagination is supported for instagram_graphql_hashtags & instagram_graphql_user_posts targets. First response returns pagination information - existence of multiple pages & end cursor of the current page. Providing this cursor value with a subsequent request will fetch the following page.

Retrieve parsed results via callback

GET https://scraper-api.smartproxy.com/v2/task/{Task_ID}/results?type=parsed

Retrieve raw HTML results via callback

GET https://scraper-api.smartproxy.com/v2/task/{Task_ID}/results?type=raw