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

  1. Go to: https://developer.linkedin.com/apps

  2. Create a new app

Configure the app:

  • Products tab:

    • Add "Share on LinkedIn" (required for w_member_social scope)

  • 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/callback
    
  • Auth URL:

    https://www.linkedin.com/oauth/v2/authorization
    
  • Access Token URL:

    https://www.linkedin.com/oauth/v2/accessToken
    
  • Scope:

    openid profile email w_member_social
    
  • Client 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:

  1. Click Get New Access Token

  2. Log in to LinkedIn and authorize the app

  3. Copy the access_token

👉 Token validity: ~2 months


4. Get Your Person URN

  1. Decode id_token using https://jwt.io

  2. Extract the sub field

Format:

urn:li:person:<sub_value>

This will be used as the author in API requests.


5. Suggested n8n Workflow

Typical flow:

  1. Webhook / Trigger → receive input

  2. Validate + Normalize → clean data

  3. Message a model → generate post content

  4. Generate an image → optional AI image

  5. Register Upload LinkedIn

  6. Code node → extract uploadUrl + asset

  7. Upload Binary → upload image

  8. Code node → build JSON body

  9. 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: PUT

  • URL:

    {{ $json.uploadUrl }}
    

Settings:

  • Body Content Type: n8n Binary File

  • Input Data Field Name: data

  • Content-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/json

  • Body:

={{ 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

  • uploadUrl expires quickly → upload immediately

  • Keep credentials secure

  • For company pages:

    • Use:

      urn:li:organization:<ID>
      
    • Requires admin permissions

  • Ensure LinkedIn-Version matches API version


14. Conclusion

The most stable approach:

  1. Create a LinkedIn App

  2. Get access token via Postman

  3. Use n8n HTTP Request nodes to:

    • Register upload

    • Upload image

    • Publish post via ugcPosts API