Actor picture

Instagram IDs to username


Convert Instagram ID numbers back to usernames

No credit card required

Author's avatarPaulo Cesar
  • Modified
  • Users162
  • Runs24,973
Actor picture
Instagram IDs to username


root = true

indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf


    "extends": "@apify"


# This file tells Git which files shouldn't be added to source control



# First, specify the base Docker image. You can read more about
# the available images at
# You can also use any other image from Docker Hub.
FROM apify/actor-node:16

# Second, copy just package.json and package-lock.json since it should be
# the only file that affects "npm install" in the next step, to speed up the build
COPY package*.json ./

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
 && npm install --only=prod --no-optional \
 && echo "Installed NPM packages:" \
 && (npm list --only=prod --no-optional --all || true) \
 && echo "Node.js version:" \
 && node --version \
 && echo "NPM version:" \
 && npm --version

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./

# Optionally, specify how to launch the source code of your actor.
# By default, Apify's base Docker images define the CMD instruction
# that runs the Node.js source code using the command specified
# in the "scripts.start" section of the package.json file.
# In short, the instruction looks something like this:
# CMD npm start


    "title": "Input schema for the apify_project actor.",
    "type": "object",
    "schemaVersion": 1,
    "properties": {
        "ids": {
            "title": "Instagram Ids",
            "type": "array",
            "default": [],
            "prefill": ["297604134"],
            "description": "Get the usernames of given Instagram Ids",
            "editor": "stringList"
    "required": []

# Instagram IDs to usernames

This actor allows you to convert a list of Instagram user IDs to their appropriate usernames. 

When scraping posts or comments, Instagram often doesn't give you final user username but only their numerical representation.
This actor allows you easily convert them and adds also general user data.

## Input
Input is a list of user IDs, e.g.
    "ids": ["898537494"]

You don't need to use JSON format, the actor allows you to use visual interface

## Webhook

You can point other Instagram scrapers that don't have the username directly to this actor, and it will generate a dataset enriched with the user data for you!


When you call this actor from the webhook, it will write the dataset ID back to your run, under `DATASET_ID` key in the Key value store, and `RUN_ID` with the run 
of this actor, so you can link them together.

## Output
Output is a list of user data containing usernames and user URLs, e.g.

        "username": "chizawagames",
        "pk": 898537494,
        "profile_pic_url": "",
        "url": ""

The output is also available as CSV, Excel, Xml and other formats.

If you call it using a actor, like, it will append the user info on the datasets from it. 


    "env": { "npm_config_loglevel": "silent" }


// This is the main Node.js source code file of your actor.

// Import Apify SDK. For more information, see
const Apify = require('apify');

const { log } = Apify.utils;

const isNumber = (s) => +s == s;
const addRequest = (id, userData) => ({ url: `${id}/info/`, userData });

Apify.main(async () => {
    const { ids, resource } = await Apify.getInput();

    const requestQueue = await Apify.openRequestQueue();
    let count = 0;

    if (resource?.defaultDatasetId) {
        const dataset = await Apify.openDataset(resource.defaultDatasetId);

        await dataset.forEach(async (item) => {
            const id = [

            if (id[0]) {
                await requestQueue.addRequest(addRequest(id[0], item));

        if (resource?.defaultKeyValueStoreId) {
            const kv = await Apify.openKeyValueStore(resource?.defaultKeyValueStoreId);
            const { defaultDatasetId, actorRunId } = Apify.getEnv(); 
            await Promise.all([
                kv.setValue('DATASET_ID', defaultDatasetId),
                kv.setValue('RUN_ID', actorRunId),

    for (const id of (ids ?? [])) {
        await requestQueue.addRequest(addRequest(id));

    const proxyConfiguration = await Apify.createProxyConfiguration({
        groups: ['RESIDENTIAL'],

    const idCount = await requestQueue.getInfo().then(({ totalRequestCount }) => totalRequestCount || count);`Going to fetch information for ${idCount} ids`);

    const crawler = new Apify.CheerioCrawler({
        preNavigationHooks: [async (context, requestAsBrowserOptions) => {
            requestAsBrowserOptions.headers = {
                "Accept": "*/*",
                "Alt-Used": "",
                "Accept-Language": "en-US,en",
                "X-IG-App-ID": "936619743392459",
                "X-ASBD-ID": "198387",
                "X-IG-WWW-Claim": "0",
                "Origin": "",
                "Referrer": "",
        handlePageFunction: async (context) => {
            const { request, json } = context;

            if (json?.status !== "ok") {
                throw new Error(`Got wrong status "${json?.status ?? json?.message ?? '-'}"`);

            if (!json?.user) {
                throw new Error(`Missing user property from response`);

            await Apify.pushData({ 
                url: `${json.user.username}`,



    "name": "project-empty",
    "version": "0.0.1",
    "description": "This is a boilerplate of an Apify actor.",
    "dependencies": {
        "apify": "^2.3.2"
    "scripts": {
        "start": "node main.js",
        "lint": "./node_modules/.bin/eslint ./src --ext .js,.jsx",
        "lint:fix": "./node_modules/.bin/eslint ./src --ext .js,.jsx --fix",
        "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
    "author": "It's not you it's me",
    "license": "ISC"