To validate profile URL input before sending an API request, check four things: it parses as an http or https URL, the host is linkedin.com or a subdomain of it, the first path segment is exactly in, and a profile name follows /in/. Those checks follow the URL rules in ProfileHunt's docs, so you catch non-profile links in your own code instead of as a 422 invalid_url. Below are the rules, a quick regex, and a full parser in JavaScript and Python.
For what a profile API does with the URL once it's accepted, see what a LinkedIn profile API is.
Key takeaways
- Validation is four checks. Scheme, host,
/in/path, a name after it. Everything after the name (slashes, extra path, query strings) can stay. - A 422 is free in credits, not in time. Each rejected call is still a network round trip your code could have skipped.
- Validation can't tell you a profile exists. A well-formed URL for a deleted profile passes, then comes back
gone, uncharged. - Use the parser, not only a regex. A regex is a good first pass for a form field; the parser below follows the documented URL rules.
What the API Accepts as a Profile URL
The profile endpoint docs define the input as linkedin.com/in/ followed by the profile's name. It may include or leave out https:// and www., use a country subdomain such as uk.linkedin.com, and end with a slash, extra path or query string. Anything else, including company pages and bare usernames, gets 422 invalid_url. A client-side validator turns that into checks you can run locally:
| Rule | Passes | Fails |
|---|---|---|
Scheme is http or https (or none) | https://…, http://…, www.linkedin.com/… | ftp://…, mailto:…, javascript:… |
Host is linkedin.com or ends in .linkedin.com | www., uk., bare linkedin.com | evillinkedin.com, linkedin.com.evil.com |
First path segment is exactly in | /in/williamhgates | /company/…, /pub/…, /sales/… |
A name follows /in/ | /in/williamhgates | /in/ |
| Sanity limits (our choice): name 2–100 characters once decoded | ab, jos%C3%A9 | a, a 101-character name |
| Sanity limits (our choice): whole input at most 500 characters | almost everything | pasted paragraphs |
Anything after the name can stay: /details/experience/, ?trk=…. Compare the host case-insensitively, as URL hosts are, and check the in segment exactly as the docs write it.
What Gets a 422, and What Doesn't
On the single endpoint, a URL that isn't a linkedin.com/in/ profile URL gets 422 with {"error":"invalid_url"} and no credit is used.
In a batch, a bad URL doesn't fail the request. It is marked invalid_url in the results and never queued. The whole batch is refused with 422 invalid_batch only when urls is missing, empty, over 100, or holds something other than strings.
Two outcomes are not validation failures, and it helps to keep them apart:
| Answer | What it means | Fix it with validation? |
|---|---|---|
422 invalid_url | The input isn't a profile URL. | Yes |
200 status: "gone" | Well-formed URL, no public profile there. | No, only a lookup can tell |
200 status: "unavailable" | LinkedIn didn't serve it just then. | No, retry later |

Why Validating First Saves Round Trips
A rejected URL costs no credits, but three costs remain.
Rate limit. Your key has 60 requests a minute. A list with 20% junk URLs, sent one by one, spends a fifth of its calls on answers you could have computed locally. The rate limit docs cover the 60-per-minute rule.
Latency and feedback. A form that checks the URL as the user types can say "that's a company page" instantly. Waiting for the server adds a round trip and a vaguer message.
Batch hygiene. Each invalid URL in a batch takes one of its 100 slots. Filtering first fits more real profiles per batch.
A Quick Regex for Forms and Spreadsheets
When all you have is a pattern field, this regex catches the common shape:
const LINKEDIN_PROFILE = /^(?:https?:\/\/)?(?:[a-z0-9-]+\.)*linkedin\.com\/in\/[^\/?#\s]{2,100}(?:[\/?#]\S*)?$/
It accepts the usual forms with or without scheme, subdomain, trailing slash or query string, and rejects company pages, bare usernames, evillinkedin.com and /IN/. It is deliberately simple, so it disagrees with the full parser below on rare input: it refuses uppercase letters in the scheme or host (HTTP://, LinkedIn.com) and port numbers, which the parser accepts, and it allows a percent-encoded name that is too short once decoded, which the parser refuses. Use it as a first pass, then run the parser.
The Full Check in JavaScript
This parser applies the rules above. It returns the profile name after /in/, encoded once, or null for input to reject before calling the API:
export function slugFromUrl(input) {
const raw = input.trim()
if (!raw || raw.length > 500) return null
let u
try { u = new URL(/^[a-z][a-z0-9+.-]*:/i.test(raw) ? raw : `https://${raw}`) } catch { return null }
if (u.protocol !== "https:" && u.protocol !== "http:") return null
const host = u.hostname.toLowerCase()
if (host !== "linkedin.com" && !host.endsWith(".linkedin.com")) return null
const [first, slug] = u.pathname.split("/").filter(Boolean)
if (first !== "in" || !slug) return null
let name
try { name = decodeURIComponent(slug) } catch { name = slug }
if (name.length < 2 || name.length > 100) return null
return encodeURIComponent(name)
}
slugFromUrl("www.linkedin.com/in/williamhgates/") // "williamhgates"
slugFromUrl("https://www.linkedin.com/company/microsoft") // null
It runs in Node.js, Bun, Deno and browsers, since it only uses the standard URL class.
The Same Check in Python
Python's urlsplit follows older URL rules than browsers, so a few extra lines make it agree with the JavaScript version:
import re
from urllib.parse import urlsplit, unquote, quote
SPACE = " \t\n\v\f\r -
"
TRIM = re.compile(f"^[{SPACE}]+|[{SPACE}]+$")
def slug_from_url(value):
"""The profile name after /in/, encoded once, or None for input to reject."""
raw = TRIM.sub("", value)
if not raw or len(raw.encode("utf-16-le")) // 2 > 500:
return None
if not re.match(r"^[a-z][a-z0-9+.-]*:", raw, re.I):
raw = "https://" + raw
m = re.match(r"^(https?):[\\/]*(.*)$", raw, re.I | re.S)
if not m:
return None
try:
u = urlsplit("https://" + m[2])
host = (u.hostname or "").lower()
except ValueError:
return None
if host != "linkedin.com" and not host.endswith(".linkedin.com"):
return None
parts = [p for p in u.path.split("/") if p]
if len(parts) < 2 or parts[0] != "in":
return None
slug = parts[1]
try:
if re.search(r"%(?![0-9A-Fa-f]{2})", slug):
raise UnicodeDecodeError("utf-8", b"", 0, 1, "broken escape")
name = unquote(slug, errors="strict")
except UnicodeDecodeError:
name = slug
if not 2 <= len(name.encode("utf-16-le")) // 2 <= 100:
return None
return quote(name, safe="-_.!~*'()")
Lengths are counted in UTF-16 units, as JavaScript counts them, so names with emoji are judged the same way.
Real Results: Both Parsers Against Awkward Inputs
We ran the Python parser and the regex against 69 deliberately awkward inputs and compared each answer with the JavaScript parser's: uppercase hosts, ports, user info, tabs inside the host, broken percent escapes, emoji names, look-alike domains and more.
| Version | Agrees with the JavaScript parser | Differs on |
|---|---|---|
| JavaScript parser | 69 of 69 (the reference) | nothing |
| Python parser | 65 of 69 | .. path segments, backslashes inside the path, a trailing NUL character |
| Regex | 53 of 69 | ports, user info, uppercase letters in the scheme or host, encoded names too short once decoded |
The four Python differences are input no person types by hand, and the API still has the final say.
What Most Guides Get Wrong About URL Validation
They check that the string contains "linkedin.com". That passes evillinkedin.com/in/x and linkedin.com.evil.com/in/x. Check the parsed host instead: equal to linkedin.com or ending in .linkedin.com.
They lowercase the whole URL, or match case-insensitively. The host is case-insensitive, but the path is better checked as written: the docs define the form as linkedin.com/in/, so test for exactly that. Lowercase only the copy you use as a dedupe key.
They reject anything with a trailing path or query string. Share links from the LinkedIn app carry tracking parameters, and profile section links end in /details/experience/. The API accepts both. A validator that rejects them throws away good rows.
Myth vs Reality
| Myth | Reality |
|---|---|
| A valid URL means the profile exists. | Validation checks shape. A deleted or private profile passes, then returns gone, uncharged. |
| Rejected calls are free, so validation is optional. | They use no credits, but each one is a wasted round trip, and a user waiting on a form gets a slower, vaguer answer. |
| A strict regex is safer. | Too strict drops real rows: subdomains, tracking parameters, section paths. |
lnkd.in short links are fine. | The host must be linkedin.com. Open the short link and send the /in/ URL it leads to. |
Old /pub/ URLs still work. | Only /in/ is accepted. Open a /pub/ link and copy the /in/ URL it redirects to. |

Advanced: Tell Users Why, Not Just "Invalid"
A validator that only says "invalid" sends people back to guess. The rules above map to messages someone can act on, and the order matters, because the first failing rule is the useful one:
| First rule that fails | Message to show |
|---|---|
No . or / at all | "That's a username. Write it as linkedin.com/in/name." |
| Host isn't linkedin.com | "Not a LinkedIn link." |
Path starts /sales/ or /talent/ | "A Sales Navigator or Recruiter link. Open the person and copy their public profile URL." |
Path starts /company/, /school/ or /showcase/ | "A company or school page, not a person." |
Path starts /pub/ | "An old /pub/ link. Open it and copy the /in/ URL it redirects to." |
Nothing after /in/, or wrong length | "No profile name after /in/, or it's too short or long." |
Validate in the form (instant feedback), at import time (one report per CSV) and on your server before calling the API; sending a profile URL from a form, CRM or sheet shows where those checks sit. ProfileHunt's free LinkedIn URL cleaner gives a reason like these for every line of a pasted list that isn't a profile link, in your browser.
Where ProfileHunt Fits
ProfileHunt is a LinkedIn Profile API: public LinkedIn profile URL in, JSON out. Its URL rules are loose where people are messy (scheme, subdomain, trailing path, tracking parameters) and strict where it matters (a real linkedin.com host and an /in/ profile).
Nothing that fails validation is ever charged, and neither are profiles that come back gone or unavailable. You pay for profiles found: $0.50 per 1,000, from prepaid credits that never expire.
Getting Started
Sign in for an API key and 100 free credits with a work email, drop one of the parsers above into your code, and send what passes. The error reference lists every status the API can return. How to write the URL inside the JSON, accents and spreadsheet links included, is in formatting a LinkedIn profile URL in an API payload, and the request bodies themselves are in LinkedIn profile API request body examples. For the fundamentals, start with what a LinkedIn profile API is.
Frequently asked questions
What is a valid LinkedIn profile URL format?
https://www.linkedin.com/in/<name>. The scheme, www., a country subdomain, a trailing slash and query strings are all optional extras the API accepts.
What regex matches a LinkedIn profile URL?
The regex in the section above matches the common forms. Use it as a first pass and a URL parser for the final check, because the regex refuses ports and uppercase hosts that a URL parser handles.
How do I check if a LinkedIn profile URL is valid before calling an API?
Parse it with a URL parser, check that the host is linkedin.com or a subdomain, that the path starts with /in/, and that a profile name follows it. The JavaScript and Python functions above do exactly that.
Does an invalid LinkedIn URL cost credits?
No. ProfileHunt answers 422 invalid_url on a single call and invalid_url inside a batch, and neither uses a credit. Validating first still saves the round trip.
Can I tell if a LinkedIn profile exists without calling the API?
No. A URL can be perfectly formed and still point at a deleted, private or never-created profile. Only a lookup tells you, and with ProfileHunt a gone answer costs nothing.


