How to Connect n8n with LinkedIn
This guide walks you through how to connect the LinkedIn API with n8n to automatically publish posts, including authentication, image upload, and content publishing.
1. Overview
Goal:
Automatically post content to LinkedIn using n8n.
Approach:
Use the LinkedIn API via the HTTP Request node in n8n.
Important note:
In some cases, n8n Cloud does not allow direct use of LinkedIn OAuth credentials inside the HTTP Request node.
→ Workaround: manually retrieve an access token using Postman.
2. Create a LinkedIn App
Create a new app
Configure the app:
Products tab:
Add "Share on LinkedIn" (required for
w_member_socialscope)
Auth tab:
Copy:
Client ID
Client Secret
Authorized Redirect URLs:
https://oauth.pstmn.io/v1/callback (for Postman) https://oauth.n8n.cloud/oauth2/callback (for n8n Cloud)
Required scopes:
openid
profile
email
w_member_social
3. Get Access Token Using Postman
Why Postman?
n8n may block OAuth credentials in HTTP Request nodes, so we retrieve the token manually.
OAuth2 Setup in Postman:
Grant Type: Authorization Code
Callback URL:
https://oauth.pstmn.io/v1/callbackAuth URL:
https://www.linkedin.com/oauth/v2/authorizationAccess Token URL:
https://www.linkedin.com/oauth/v2/accessTokenScope:
openid profile email w_member_socialClient Authentication:
Send client credentials in body
⚠️ Important:
If you don’t choose “Send client credentials in body”, you may get:
client_secret is missing
Steps:
Click Get New Access Token
Log in to LinkedIn and authorize the app
Copy the
access_token
👉 Token validity: ~2 months
4. Get Your Person URN
Decode
id_tokenusing https://jwt.ioExtract the
subfield
Format:
urn:li:person:<sub_value>
This will be used as the author in API requests.
5. Suggested n8n Workflow
Typical flow:
Webhook / Trigger → receive input
Validate + Normalize → clean data
Message a model → generate post content
Generate an image → optional AI image
Register Upload LinkedIn
Code node → extract
uploadUrl+assetUpload Binary → upload image
Code node → build JSON body
Post LinkedIn → publish post
6. Required Headers
Use these headers for all LinkedIn API requests:
Authorization: Bearer <access_token>
LinkedIn-Version: 202504
X-Restli-Protocol-Version: 2.0.0
Content-Type: application/json
7. Register Image Upload
Endpoint:
POST https://api.linkedin.com/v2/assets?action=registerUpload
Body:
{
"registerUploadRequest": {
"recipes": ["urn:li:digitalmediaRecipe:feedshare-image"],
"owner": "urn:li:person:<PERSON_ID>",
"serviceRelationships": [
{
"relationshipType": "OWNER",
"identifier": "urn:li:userGeneratedContent"
}
]
}
}
8. Extract Upload URL (Code Node)
const uploadMechanism = $input.item.json.value.uploadMechanism;
const key = 'com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest';
const uploadUrl = uploadMechanism[key].uploadUrl;
const asset = $input.item.json.value.asset;
return {
json: { uploadUrl, asset },
binary: $('Generate an image1').item.binary
};
⚠️ Important:
You must pass the binary data, or you’ll get:
node input data does not contain a binary file
9. Upload Image (Binary)
Method:
PUTURL:
{{ $json.uploadUrl }}
Settings:
Body Content Type:
n8n Binary FileInput Data Field Name:
dataContent-Type:
image/png
10. Build Post Body (Code Node)
To avoid JSON errors, construct the object in a Code node:
const title = $('Validate + Normalize').item.json.title;
const aiText = $('Message a model').item.json.content[0].text;
const asset = $('Register Upload LinkedIn').item.json.value.asset;
return {
json: {
author: 'urn:li:person:<ID>',
lifecycleState: 'PUBLISHED',
specificContent: {
'com.linkedin.ugc.ShareContent': {
shareCommentary: {
text: title + '\\n\\n' + aiText
},
shareMediaCategory: 'IMAGE',
media: [{
status: 'READY',
media: asset
}]
}
},
visibility: {
'com.linkedin.ugc.MemberNetworkVisibility': 'PUBLIC'
}
}
};
11. Publish Post to LinkedIn
Endpoint:
POST https://api.linkedin.com/v2/ugcPosts
Settings:
Content-Type:
application/jsonBody:
={{ JSON.stringify($json) }}
12. Common Errors & Fixes
Error | Cause | Fix |
|---|---|---|
credential not accessible | Not shared properly | Move to Global |
OAuth blocked in HTTP node | n8n restriction | Use manual token |
EMPTY_ACCESS_TOKEN (401) | Missing Authorization | Add Bearer token |
Invalid URL | Expression issue | Extract via Code node |
Bad control character | JSON formatting | Use JSON.stringify |
binary file not found | Missing binary data | Pass binary correctly |
client_secret is missing | Wrong Postman config | Fix client auth |
redirect_uri mismatch | Not registered | Add to LinkedIn app |
13. Important Notes
Access tokens expire → must refresh manually
uploadUrlexpires quickly → upload immediatelyKeep credentials secure
For company pages:
Use:
urn:li:organization:<ID>Requires admin permissions
Ensure
LinkedIn-Versionmatches API version
14. Conclusion
The most stable approach:
Create a LinkedIn App
Get access token via Postman
Use n8n HTTP Request nodes to:
Register upload
Upload image
Publish post via
ugcPostsAPI