LINKEDIN PROFILE API

JavaScript Example: LinkedIn Profile URL to JSON

The shortest working JavaScript example that turns a LinkedIn profile URL into JSON, explained line by line, and where it runs: Node, Bun, Deno, edge functions.

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

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

JavaScript Example: LinkedIn Profile URL to JSON

The shortest JavaScript example for converting a LinkedIn profile URL into JSON is a single fetch call: POST the URL to https://api.profilehunt.dev/v1/profile with your API key, and the response body is the public profile as JSON. It runs anywhere JavaScript has fetch and a place to keep a secret: Node.js, Bun, Deno, serverless and edge functions. It does not run in a web page, and this post explains why and what to do instead.

For background on how the URL becomes data, see what a LinkedIn profile API is.

Key takeaways

  • About ten lines of code. One fetch, one header with the key, one JSON body with the URL.
  • Every key comes back, every time. A missing value is null and an empty list is [].
  • Server-side JavaScript only. Node, Bun, Deno and edge functions work; browser code does not, because the key would be public.
  • A browser can still trigger it. Put a small server or edge function between the page and the API.

The shortest working example, line by line

const res = await fetch("https://api.profilehunt.dev/v1/profile", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PROFILEHUNT_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ url: "https://www.linkedin.com/in/williamhgates" }),
});
const { profile } = await res.json();

Save it as profile.mjs, set PROFILEHUNT_KEY, add console.log(profile) and run node profile.mjs. Here is what each line does:

LineWhat it does
await fetch(".../v1/profile", …)Sends one HTTPS request to the profile endpoint. The top-level await works in ES modules (.mjs).
method: "POST"The endpoint takes the URL in a JSON body, so it's a POST, not a GET.
Authorization: Bearer …Your workspace API key. x-api-key: <key> works too.
process.env.PROFILEHUNT_KEYReads the key from the environment, so it never sits in source code.
"Content-Type": "application/json"Tells the API the body is JSON.
JSON.stringify({ url })The only required field. Any linkedin.com/in/ URL works, with or without https:// or www., a country subdomain, a trailing slash or a query string.
await res.json()Parses the body: { "status": "ok", "profile": { … } }.
const { profile } = …Pulls out the profile object.

What comes back

For the sample URL, the parsed JSON starts like this (shortened from a real response):

{
  "status": "ok",
  "profile": {
    "public_id": "williamhgates",
    "profile_url": "https://www.linkedin.com/in/williamhgates",
    "full_name": "Bill Gates",
    "headline": "Chair, Gates Foundation and Founder, Breakthrough Energy",
    "location": "Seattle, Washington, United States",
    "country": "US",
    "experience": [
      { "company": "Gates Foundation", "title": "Co-chair", "start_date": "2000", "end_date": null }
    ],
    "followers": 40725248,
    "connections": 8,
    "last_post_at": "2026-10-12T20:10:59.000Z",
    "scraped_at": "2026-10-13T09:00:00.000Z"
  }
}

The full object also has first_name, last_name, photo_url, about, education, languages, creator, badges, recent_posts, recent_articles, last_reaction_at, recent_reactions, last_comment_at, recent_comments and last_active_at. The LinkedIn profile JSON schema explains each field.

Two other bodies are possible with HTTP 200: { "status": "gone", "profile": null } when there is no public profile at that URL, and { "status": "unavailable", "profile": null } when LinkedIn didn't serve it just then. Neither is charged. This example skips error handling on purpose; calling the API from Node.js adds statuses, error codes and retries.

Three runtimes on pedestals, two open and one locked behind glass

Where this JavaScript can run

The same fetch call runs in every modern JavaScript runtime. What changes is how each one reads the secret, and whether the secret stays private.

RuntimeWorks?How it reads the key
Node.js 18+Yesprocess.env.PROFILEHUNT_KEY
BunYesprocess.env.PROFILEHUNT_KEY (also Bun.env)
DenoYesDeno.env.get("PROFILEHUNT_KEY"), run with --allow-net --allow-env
Serverless functions (AWS Lambda, Vercel Functions)YesThe platform's environment variables
Edge functions (Cloudflare Workers and similar)YesA secret bound to the function, e.g. env.PROFILEHUNT_KEY
Browser JavaScript (a web page, a React app)NoAnything sent to the browser is public

Why not in the browser

Two reasons, and either one is enough. First, the key: any value in front-end code, including build-time env vars, ends up in the JavaScript bundle where anyone can read it, and the key spends your workspace's credits. Second, the API refuses it: browsers can only call the ProfileHunt API from the ProfileHunt dashboard, so a request from your own site's page is blocked by the browser's cross-origin rules (CORS). The authentication docs state both.

An edge function the browser can call

The fix is a small function that holds the key and forwards one URL. Here it is as a Cloudflare Worker; the body is the same fetch as above:

export default {
  async fetch(request, env) {
    const { url } = await request.json();
    const res = await fetch("https://api.profilehunt.dev/v1/profile", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${env.PROFILEHUNT_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ url }),
    });
    return new Response(res.body, { status: res.status, headers: { "Content-Type": "application/json" } });
  },
};

Your page then calls your own endpoint, for example fetch("/api/profile", { method: "POST", body: JSON.stringify({ url }) }), and never sees the key. The same shape works as a Next.js Route Handler, an Express route or a Deno Deploy handler. The design questions around it, such as per-environment keys and rotation, are covered in the secure authentication pattern.

What Most Guides Get Wrong

They scrape the HTML. Many "LinkedIn profile to JSON in JavaScript" snippets fetch the profile page and parse it with Cheerio or a headless browser. That breaks whenever the page markup changes, and it puts the blocking, retries and proxy rotation on you. An API call returns the same keys every time.

They put the key in a REACT_APP_ or VITE_ variable. Those prefixes exist precisely to expose values to the browser. A secret there is a published secret.

They show the call but not the shape. Code that reads profile.experience[0].title works on the demo profile and fails on the first person whose title is null. Always look at the object's guarantees: keys present, values nullable, lists possibly empty.

Myth vs Reality

MythReality
"Converting a profile URL to JSON needs Puppeteer."A profile API does the reading. Your JavaScript sends one HTTPS request.
"Edge runtimes can't call third-party APIs."They have the standard fetch. The example above runs unchanged on Cloudflare Workers.
"If CORS blocks the call, a proxy service fixes it."A public CORS proxy would still need your key in the page. Your own server-side function is the fix.
"A JSON response means the profile was found."Check status: gone and unavailable are valid JSON with profile: null, and both are free.

Advanced: Guarding the Proxy Function

Once a browser can reach your function, anyone who finds the endpoint can make it spend your credits. Three guards keep a public-facing proxy safe.

  1. Validate before forwarding. Reject anything that isn't a linkedin.com/in/ URL in the function itself. The API would answer 422 invalid_url without charging, but checking first saves a round trip and keeps junk out of your logs. A regex and normalizer are in validating profile URL input.
  2. Authenticate your own users. Only forward requests from signed-in users of your app, and rate limit them per user. The ProfileHunt limit is 60 requests a minute per key, shared by everyone who uses your function.
  3. Return less than you receive. If the page only shows name, headline and current company, send only those fields to the browser.

A wall with a hatch, the key kept on a shelf behind it, and an arrow passing through

One more edge-specific detail: some edge platforms cap how long a function may wait on an upstream request. A live profile read usually takes a few seconds, so check your platform's limit, and treat a cut-off request like a 504, which is free and safe to retry.

Where ProfileHunt Fits

ProfileHunt is a LinkedIn Profile API: public LinkedIn profile URL in, JSON out. That makes the JavaScript side small: the ten lines above are the whole integration, in any runtime with fetch.

You pay only for profiles found, at $0.50 per 1,000 profiles, with no subscription and credits that never expire. The data is the public view a logged-out visitor sees, so there are no emails or phone numbers, no titles for past roles, and connections stops at 500.

Getting Started

  1. Sign in at profilehunt.dev/login for 100 free credits with a work email (10 with a personal one).
  2. Paste a profile URL into the playground to see the JSON without writing code.
  3. Run the example above with your key, then follow the quickstart.

For what each field means and where the data comes from, go back to the LinkedIn profile API overview.

Frequently asked questions

How do I convert a LinkedIn profile URL to JSON in JavaScript?

Send the URL in a POST to a LinkedIn profile API such as https://api.profilehunt.dev/v1/profile with your API key, and call res.json() on the response. The profile field is the profile as JSON.

Can I call a LinkedIn profile API from the browser?

No. Your API key would be visible to every visitor, and the ProfileHunt API only accepts browser requests from its own dashboard. Call it from a server or edge function and have your page call that.

Does this JavaScript example work in Cloudflare Workers?

Yes. Workers have the standard fetch. Store the key as a secret, read it from env, and use the same request body.

What does the API return if the LinkedIn profile doesn't exist?

HTTP 200 with { "status": "gone", "profile": null }. It is not charged, and retrying won't change the answer.

Do I need a LinkedIn account to get profile JSON in JavaScript?

No. ProfileHunt reads the public profile view and never uses your LinkedIn account, cookie or Sales Navigator seat.

Get API key 100 free credits with a work email