I'm developing a Next.js application hosted on a cloud server (Ubuntu 22.04, Node.js v22.17.0), and I'm using the native fetch (which uses Undici under the hood). When trying to call the LinkedIn API endpoint https://api.linkedin.com/v2/me, I'm encountering the following error:
[cause]: Error
at makeNetworkError (node:internal/deps/undici/undici:9277:35)
at httpRedirectFetch (node:internal/deps/undici/undici:10825:32)
at httpFetch (node:internal/deps/undici/undici:10785:28)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async node:internal/deps/undici/undici:10522:20
at async mainFetch (node:internal/deps/undici/undici:10512:20)
Sample code:
const response = await fetch('https://api.linkedin.com/v2/me', {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
});
Things I've Tried:
Valid OAuth2 access token is being passed (works fine from local dev).
The same fetch request works from my local machine (Mac).
I can curl / telnet / openssl from the server to api.linkedin.com:443 — it connects successfully.
Tested with increased fetch timeout and retries - still fails.
Questions:
What exactly causes makeNetworkError in undici when using fetch with HTTPS?
Why would this work locally but fail on a cloud-hosted server?
Are there any known network restrictions or IP blocks from LinkedIn's side?
Could this be caused by redirect handling or TLS handshake issues?