Create a Simple Post (User) ( linkedin)
One script reply has been approved by the moderators Verified

Created by aureliemysticfairy88 296 days ago Viewed 65 times 0 Points

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.70.1/mod.ts"

export async function main(
  auth: wmill.Resource<'linkedin'>,
  content: string,
  visibility: 'PUBLIC' | 'CONNECTIONS' = 'PUBLIC'
) {
  const entityResponse = await fetch('https://api.linkedin.com/v2/me', {
    headers: { Authorization: "Bearer " + auth.token },
  })
  const entityId = (await entityResponse.json()).id

  const url = new URL('https://api.linkedin.com/v2/ugcPosts')
  const body = JSON.stringify({
    author: `urn:li:person:${entityId}`,
    lifecycleState: 'PUBLISHED',
    specificContent: {
      'com.linkedin.ugc.ShareContent': {
        shareCommentary: {
          text: content
        },
        shareMediaCategory: 'NONE'
      }
    },
    visibility: {
        'com.linkedin.ugc.MemberNetworkVisibility': visibility
    }
  })
  const response = await fetch(url, {
    method: "POST",
    headers: {
      Authorization: "Bearer " + auth.token,
      'X-Restli-Protocol-Version': '2.0.0'
    },
    body
  })

  if(!response.ok) {
    throw Error(await response.text())
  }
  return await response.json()
}

Submitted by adam186 109 days ago

Edited 29 days ago

No comments yet

Login to be able to comment