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:

Endpoint

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

Instagram GraphQL profile

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_profile
usernamestring✅Instagram profile namenba
localestringlanguage locale
geostringgeolocation

Return value JSON:

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

Examples

{
    "target": "instagram_graphql_profile",
    "username": "nba"
}
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"username\": \"nba\", \"target\": \"instagram_graphql_profile\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/nba',
  	'target': 'instagram_graphql_profile',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/nba',
  	'target' => 'instagram_graphql_profile',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL User Posts

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_user_posts
usernamestring✅Instagram user profile name.nba
localestringlanguage locale
countstringpost count: min 12, max 50 per response50
cursorstringnext page string (end_cursor value in response)QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA
geostringgeolocation

Return value JSON:

  • Basic information (name, description, follower count).
  • Up to 50 most recent posts. Amount can be specified with count parameter.

Examples

curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"username\": \"nba\", \"target\": \"instagram_graphql_user_posts\",\"locale\": \"en-us\", \"cursor\": \"QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA\", \"count\": \"50\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'username': 'nba',
  	'target': 'instagram_graphql_user_posts',
  	'locale': 'en-us',
  	'count': '50',
  	'cursor':'QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'username' => 'nba',
  	'target' => 'instagram_graphql_user_posts',
  	'count' => '50',
  	'locale' => 'en-us',
  	'cursor' => 'QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL User Following

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_user_following
usernamestring✅Instagram profile usernamenba

Return value:

  • JSON containing the number of profiles this user is following (no exact profile names).

Instagram GraphQL User Followers

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_user_followers
usernamestring✅Instagram profile usernamenba

Return value:

  • JSON containing the number of followers this user has (no exact follower handles).

Instagram GraphQL post

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_post
urlurl✅Instagram post URLhttps://www.instagram.com/p/ChYHpdAvnob
localestringlanguage locale
geostringgeolocation

Return value JSON:

  • Basic information (post description, likes, comment count, author, related posts).
  • The top 10 comments (Instagram sorts these by its own ranking).

Examples

{
    "target": "instagram_graphql_post",
    "query": "tasty"
}
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"url\": \"https://www.instagram.com/p/ChYHpdAvnob", \"target\": \"instagram_graphql_post\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/p/ChYHpdAvnob',
  	'target': 'instagram_graphql_post',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/p/ChYHpdAvnob',
  	'target' => 'instagram_graphql_post',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL hashtag

📘

Note that there are two separate hashtag-related targets:

  • instagram_graphql_hashtag
  • instagram_graphql_hashtags

Both return similar hashtag information, but share a different data format. If one target does not fit your use case, the other target can be used.

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_hashtags
querystring✅
localestring
geostring

Examples

{
    "target": "instagram_graphql_hashtag",
    "query": "tasty"
}
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"url\": \"https://www.instagram.com/explore/tags/nba/\", \"target\": \"instagram_graphql_hashtag\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/explore/tags/nba/',
  	'target': 'instagram_graphql_hashtag',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/explore/tags/nba/',
  	'target' => 'instagram_graphql_hashtag',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL Hashtags

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

Return value JSON:

  • Basic information (description, shortcodes, image URLs, like count, comment count).
  • Up to 155 most recent posts. Amount can be specified with count parameter.

Payload type: JSON

ParameterTypeRequiredDescriptionExample
targetstring✅targetinstagram_graphql_hashtags
querystring✅Instagram hashtagpizza
localestringlanguage locale
countstringpost count: min 12, max 50 per response50
cursorstringnext page string (end_cursor value in response)QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw
geostringgeolocation
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"query\": \"pizza\", \"target\": \"instagram_graphql_hashtags\",\"locale\": \"en-us\", \"cursor\": \"QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw\", \"count\": \"50\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'query': 'pizza',
  	'target': 'instagram_graphql_hashtags',
  	'locale': 'en-us',
  	'count': '50',
  	'cursor':'QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'query' => 'pizza',
  	'target' => 'instagram_graphql_hashtags',
  	'count' => '50',
  	'locale' => 'en-us',
  	'cursor' => 'QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Create callback for Instagram post

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

Payload type: JSON

ParameterTypeRequiredDescriptionExamples
targetstring✅targetinstagram_graphql_post
urlurl✅Instagram post URLhttps://www.instagram.com/p/ChYHpdAvnob
localestringlanguage locale
geostringgeolocation

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\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/p/ChYHpdAvnob/',
  	'target': 'instagram_graphql_post',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/task',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/p/ChYHpdAvnob/',
  	'target' => 'instagram_graphql_post',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/task');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

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