javascriptnode.jsaxiosescapinglinkedin-api

LinkedIn Post API: post text get's cut off if contains "()"


I'm trying to post on LinkedIn via their API. Endpoint https://api.linkedin.com/rest/posts.

The integration is working fine until I try to post something with a ( character. Redigated example:

  {
  author: '',
  commentary: 'a line\n' +
    '\n' +
    'another line...\n' +
    '\n' +
    '\n' +
    'This gets posted (it will get cut off from here)\n' +
    'another line\n'
  ...
}

If tried url encoding the string as well as JSON.stringify the whole object. The first gets posted with all the escaped characters still there (i.e.: a%20line%20) and will also get cut off since encodeURI doesn't escape (). The latter will throw an error in the API saying something like "commentary string formatted wrong".

Any ideas how to solve this?

Edit:

This here mentions the escapes at the very bottom: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/little-text-format?view=li-lms-2022-08#text

However: If I do \\( the API will come back with "The input string format is invalid"


Solution

  • Ok, so the issue was indeed some weird escaping stuff.

    Solved by running text.replace(/[\(*\)\[\]\{\}<>@|~_]/gm, (x) => "\\" + x) on the string.