LINKEDIN PROFILE API

How to Submit LinkedIn URLs in Bulk for JSON Enrichment

Submitting LinkedIn profile URLs in bulk: chunk lists over 100, dedupe, keep order, map results to rows, write JSONL and resume a failed run safely.

By Surender Kumar, GTM Engineer, ProfileHunt · Published · 9 min read

Also in: Español · Português (Brasil) · Deutsch · Français · 简体中文 · हिन्दी · العربية · বাংলা · Русский · Bahasa Indonesia · اردو · 日本語 · मराठी · Tiếng Việt · తెలుగు · Hausa · Türkçe · தமிழ் · 한국어

How to Submit LinkedIn URLs in Bulk for JSON Enrichment

To submit LinkedIn profile URLs in bulk for JSON enrichment, clean and deduplicate the list first, split it into chunks of at most 100, send each chunk as one batch request, and map every result back to its row by position. Write the results as JSON Lines, one line per input row, and save each batch id the moment it is created so a crashed run can resume without creating, and paying for, the same batch twice.

Those mechanics are what this post covers, with a resumable Python script. The endpoint's request and response format is in the batch LinkedIn profile API reference; if you just want a CSV in and a CSV out, the CSV enrichment guide is shorter.

Key takeaways

  • Dedupe on the profile slug, not the raw string. uk.linkedin.com/in/x/ and https://www.linkedin.com/in/x are the same profile.
  • Chunks of 100, order kept. results[i] belongs to urls[i] within each batch, which is all the mapping you need.
  • JSONL keeps the whole profile. One line per input row, with the row ID, the status and the full profile object.
  • Save batch IDs before polling. A batch stays readable for 30 days, so a restart reads it back instead of buying it again.

Step 1: Normalize and deduplicate the URLs

A bulk list from a CRM or spreadsheet carries the same person in several spellings: with and without https://, a country subdomain such as uk.linkedin.com, a trailing slash, a ?trk= query string. The API accepts all of them and reduces each to the /in/<slug> part. It also skips a repeated profile inside one batch (status duplicate, never charged). It cannot see repeats across two batches, so a list with the same person in chunk 1 and chunk 40 pays twice unless you dedupe first.

Reduce every URL to its slug with a rule that matches the documented URL forms: any linkedin.com host, a path starting with /in/, the next path segment as the slug.

from urllib.parse import urlsplit, unquote

def profile_key(url):
    raw = url.strip()
    if "://" not in raw:
        raw = "https://" + raw
    parts = urlsplit(raw)
    host = (parts.hostname or "").lower()
    if host != "linkedin.com" and not host.endswith(".linkedin.com"):
        return None  # would come back invalid_url
    segments = [s for s in parts.path.split("/") if s]
    if len(segments) < 2 or segments[0] != "in":
        return None
    return unquote(segments[1]).lower()

Rows whose key is None (company pages, search links, bare names) are written straight to the output as invalid_url without spending a slot in a batch.

Two spellings of the same profile reduced to one before submission

Step 2: Chunk the list and keep the order

Take the distinct keys in first-seen order and cut them into chunks of 100, the largest batch the API accepts. Sending one URL per key (the first spelling seen) and keeping a map from key to every row that uses it is what makes the mapping back trivial: the batch keeps your order, so zipping a chunk's keys with its results gives each key its result, and each key fans out to its rows.

Do not map results back by the returned profile.profile_url or public_id. Those are normalized forms (the canonical URL and the decoded name), so they rarely match the raw string you sent, and they are missing entirely when profile is null. Position never changes.

Step 3: Submit, save the batch ID, then poll

The order of these three actions is the whole resume strategy:

  1. POST /v1/profile/batches with the chunk.
  2. Write the returned batch id to a state file, keyed by chunk number, before polling.
  3. Poll GET /v1/profile/batches/<id> every few seconds until status is completed.

If the process dies between 1 and 3, the batch keeps running on the server, and its credits are already held. On restart, the state file says chunk 7 has a batch ID, so the script polls that ID instead of creating chunk 7 again. Creating it again would hold and charge the credits a second time.

Step 4: Write results as JSON Lines

JSON Lines writes one JSON object per line. It suits enrichment output because each line stands alone: appending is safe, a half-written file loses at most one line, and jq, pandas and data warehouses such as BigQuery load it directly. Write one line per input row:

{"row_id": "42", "url": "https://uk.linkedin.com/in/williamhgates/", "status": "ok", "profile": {"full_name": "Bill Gates", "headline": "Chair, Gates Foundation and Founder, Breakthrough Energy"}}
{"row_id": "43", "url": "linkedin.com/company/microsoft", "status": "invalid_url", "profile": null}

The profile object is the full response, shortened here. Every key is always present, null when the profile doesn't show it. The LinkedIn profile JSON schema guide lists every field.

The resumable script

This puts the four steps together. The input is a CSV with id and linkedin_url columns; the output is appended to a .jsonl file; progress is in batches.json. Run it again after any failure and it carries on.

import csv, json, os, sys, time, requests
from collections import defaultdict
# profile_key() from Step 1 goes here

API = "https://api.profilehunt.dev/v1/profile/batches"
HEADERS = {"Authorization": f"Bearer {os.environ['PROFILEHUNT_KEY']}"}
STATE = "batches.json"


def save(state):
    with open(STATE, "w") as f:
        json.dump(state, f)


def poll(batch_id):
    while True:
        res = requests.get(f"{API}/{batch_id}", headers=HEADERS)
        res.raise_for_status()
        batch = res.json()
        if batch["status"] == "completed":
            return batch
        time.sleep(5)


def run(src, dst):
    with open(src, newline="", encoding="utf-8") as f:
        rows = [(r["id"], r["linkedin_url"]) for r in csv.DictReader(f)]
    state = json.load(open(STATE)) if os.path.exists(STATE) else {}

    rows_by_key, first_url = defaultdict(list), {}
    for row_id, url in rows:
        key = profile_key(url)
        rows_by_key[key].append((row_id, url))
        first_url.setdefault(key, url.strip())
    keys = [k for k in first_url if k is not None]
    chunks = [keys[i:i + 100] for i in range(0, len(keys), 100)]

    with open(dst, "a", encoding="utf-8") as out:
        def write(row_id, url, status, profile):
            out.write(json.dumps({"row_id": row_id, "url": url, "status": status, "profile": profile}) + "\n")

        if not state.get("invalid_written"):
            for row_id, url in rows_by_key[None]:
                write(row_id, url, "invalid_url", None)
            out.flush()
            state["invalid_written"] = True
            save(state)

        for n, chunk in enumerate(chunks):
            entry = state.setdefault(str(n), {})
            if entry.get("done"):
                continue
            if "id" not in entry:
                res = requests.post(API, headers=HEADERS, json={"urls": [first_url[k] for k in chunk]})
                res.raise_for_status()  # 402: top up credits and run again
                entry["id"] = res.json()["id"]
                save(state)  # saved before polling: a restart reuses this batch
            batch = poll(entry["id"])
            for key, result in zip(chunk, batch["results"]):
                for row_id, url in rows_by_key[key]:
                    write(row_id, url, result["status"], result["profile"])
            out.flush()
            entry["done"] = True
            save(state)
            print(f"chunk {n + 1}/{len(chunks)}: {batch['credits_used']} credits")


if __name__ == "__main__":
    run(sys.argv[1], sys.argv[2])

The script submits chunks one after another, so it never comes close to the rate limit of 60 requests a minute. To run faster on a very large list, create several batches before polling any of them; the concurrency guide has the throughput math, and the Python workflow at scale runs this pattern on 100,000 profiles.

A marker on the next unfinished chunk in a row of completed ones

What Most Guides Get Wrong About Bulk Submission

They retry a failed run from the top. Every chunk that was already created holds or has used credits. Re-creating it pays again. Save the batch id, read it back.

They dedupe on the exact string. Exact-string dedupe misses country subdomains, trailing slashes and query strings, so the same person can land in two chunks and be charged twice.

They treat the output as a new table. Writing one line per distinct profile loses the rows that shared it. Writing one line per input row, with its row_id, makes the output join back to the source with no extra work.

Myth vs Reality

MythReality
"The API dedupes my whole list."Only inside one batch. Across chunks, deduplication is your job.
"If the script crashes, the batch is lost."It keeps running on the server and stays readable for 30 days with the batch id.
"A failed batch creation wastes credits."A 402, 429 or 503 on creation holds nothing. Fix the cause and send the same chunk again.
"Results must be matched by URL."Results are in the order sent. Position is the reliable key.
"Invalid URLs should be sent so the API can reject them."They'd come back invalid_url at no charge, but filtering them first keeps every slot of a 100-URL batch for real profiles.

Advanced: Edge Cases in Long-Running Bulk Jobs

  • The input file changes between runs. Chunk numbers in the state file refer to the chunking of one specific input. Edit the file and chunk 7 is a different set of URLs. Treat the input as frozen for the life of a run, or store each chunk's keys in the state file alongside its id.
  • A crash between writing and marking done. The output can then hold a chunk's lines twice. Because every line carries row_id, keep the last line per row_id when loading.
  • Retries of unavailable and failed. These were not charged. Collect their rows from the JSONL after the run and submit them as a new run with a new state file, ideally later in the day; what an unavailable response means has a retry schedule.
  • The 30-day window. A batch can be read for 30 days after creation, then GET returns 404. A run paused longer than that must re-submit its open chunks.
  • Workspaces. A batch can only be read with a key from the workspace that created it. Resuming with a key from another workspace returns 404, not the results.

Where ProfileHunt Fits

ProfileHunt is a LinkedIn Profile API: public LinkedIn profile URL in, JSON out. Its batch endpoint takes up to 100 URLs per request, keeps your order, skips repeats inside a batch, and keeps every batch readable for 30 days, which is what makes the resume pattern above work. You pay $0.50 per 1,000 profiles found, credits are held per batch and refunded automatically for anything not found, and there is no subscription.

The data is the public view of each profile: identity, headline, about, location, experience, education, followers, connections (capped at 500) and recent activity. It does not include emails, phone numbers or titles for past roles.

Getting Started

  1. Create an account; a work email gets 100 free credits.
  2. Set your key as PROFILEHUNT_KEY and make one call from the quickstart.
  3. Run the script on a 100-row sample, kill it halfway, and run it again to see it resume. The batch API docs list every status and error it can meet.

For the endpoint itself, the batch LinkedIn profile API reference is the starting point.

Frequently asked questions

How do I send more than 100 LinkedIn URLs to the batch API?

Split the list into chunks of 100 and create one batch per chunk. Each creation is one request against the limit of 60 a minute, so even 10,000 URLs take only 100 requests.

How do I remove duplicate LinkedIn profile URLs from a list?

Reduce each URL to the slug after /in/, ignoring the scheme, the subdomain, trailing slashes and query strings, and dedupe on that slug. Keep a map from slug to every original row so each row still gets its result.

Does the LinkedIn profile API return results in the same order I sent them?

Yes. ProfileHunt's batch results have one entry per URL sent, in the same order, including invalid and duplicate URLs.

How do I resume a bulk enrichment job that failed halfway?

Save each batch id as soon as the batch is created. On restart, poll the saved IDs instead of creating those batches again; batches stay readable for 30 days.

What is the best output format for bulk LinkedIn profile enrichment?

JSON Lines, one line per input row with the row ID, status and full profile object. It is safe to append, keeps nested fields like experience intact, and loads into pandas, jq and data warehouses directly.

Get API key 100 free credits with a work email