Problem of JSON parameters in HTTP request when trying to post to linkedin

Describe the problem/error/question

Hey chat so i’m having issues executing a http request to linkedin because of the JSON error

What is the error message (if any)?

It keeps sayong JSON parameter needs to be valid JSON. ive checked the reples on here and nothing has worked so far

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.){
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.linkedin.com/v2/ugcPosts",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "linkedInOAuth2Api",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer {AQW0a2Z0NS0FHEgvc7aqB5bHlsvn2j5IRqMRTk38rVJp7vEC3jPlHQA2A9w5ZyBpGl9quooIWqH7kLnAVVpoo3FhWBEQoeghsGMSEfp0nfTpnk1TbdpUfgl4mBzcj6ik1bvaYw9Ab-3Vl9vlH3DqAUbbngt4k-M8BC_lMdH0dTlcjopiVvWy63pNdI9rBKnFb3_FxphRu7RfO6JNMk_kCbmaKpivrrR9tnfCGw5hbfRc5Y5ydLaieeNcg24_XhV6oD5x-upVyqYg3ZzL0q5kER4iDe3KYRwCr09OAjHJdeQHo_nEMerP2qiX8LN79en4CJNGcOO5hwhGStH_nFoSnmNWAMXEfA}"
            },
            {
              "name": "X-Restli-Protocol-Version",
              "value": "2.0.0"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "=\n{\n\"author\": \"urn:li:person:hfMGWGx_ow\",\n\"lifecycleState\": \"PUBLISHED\",\n\"specificContent\": {\n\"com.linkedin.ugc.ShareContent\": {\n\"media\": [\n{\n\"media\": \"urn:li:digitalmediaAsset:C5603AQHMl0UPKaPusw\",\n\"status\": \"READY\",\n\"title\": {\n\"attributes\": [],\n\"text\": \"Sample Video Create https://drive.google.com/file/d/1MPjwpomkkOBeGx5xWPgAZfO3EYIFZFUy/view?usp=sharing\"\n}\n}\n],\n\"shareCommentary\": {\n\"attributes\": [],\n\"text\": \"{{ $json.Caption }}\"\n},\n\"shareMediaCategory\": \"VIDEO\"\n}\n},\n\"visibility\": {\n\"com.linkedin.ugc.MemberNetworkVisibility\": \"PUBLIC\"\n}\n} }}}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        64,
        176
      ],
      "id": "9a5afe71-6a90-49a5-8aab-fbc34b172c1b",
      "name": "HTTP Request1",
      "credentials": {
        "linkedInOAuth2Api": {
          "id": "Cwvr4xK4pCJjlAv4",
          "name": "LinkedIn account 2"
        },
        "linkedInCommunityManagementOAuth2Api": {
          "id": "abvivQvfwdjQCAP1",
          "name": "LinkedIn Community Management account"
        }
      }
    }
  ],
  "connections": {
    "HTTP Request1": {
      "main": [
        []
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "35ae3fe36b48e014c41aaf1c49b2748f208955a93f8c3f63d04a12883462b1b1"
  }
}

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.108.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: windows 10

Hi @Chinwe_Nwokoro welcome to the :n8n: community!


Try using this:

"text":  {{ JSON.stringify( $json.Caption ) }}

Also note that you can use the built-in Linked node to create a post,

Let me know if you still have any issues..

It still gives that same error. This is what it looks like

For the LinkedIn node I tried that and I had issues with credentials. The standard OAuth path stopped me from stopping while the community API said not enough callbacks even after I had created an app and added the client ID and secret

Hi, replace this please:

with this:

"text":  {{ JSON.stringify( $json.Title) }}

or just:

"text":  "title test"

I have done both and it’s still the same error

Should I copy the whole code on here

can you try this sample workflow:

you need to link Linkedin OAuth2 API

For this specific get URN it said forbidden something about the credentials. But I have a LinkedIn urn that I was able to get from my own httt request

Okay, let’s first ensure that authentication is working correctly.

Could you share what your scopes configuration looks like at Developers | LinkedIn

Are you trying to post to your personal account or a company account?

im trying to post on personal

1 Like

Nice! So no need for complexity, just follow these steps to set up the LinkedIn node:

Generate a Client Secret:

Go to n8n and add your LinkedIn OAuth2 API details:

Create your post:

Okay the LinkedIn node works now

Thank you so much Mohamed :folded_hands:

1 Like

Glad it worked @Chinwe_Nwokoro :tada:

Would you mind please like❤️ and marking the reply as the solution :white_check_mark:? Thanks!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.