Linkedin API /ugcPosts invalid query parameters

  api, javascript, linkedin, linkedin-api

I try to use the Linkedin API for several things including posting content on my business page. All products have been added to the Linkedin Developper platform and I use the following scopes:

  • rw_organization_admin
  • w_organization_social
  • r_liteprofile
  • r_organization_social
  • w_member_social

Here is my code:

const params = {
  author: "urn:li:organization:" + company_id,
  lifecycleState: "PUBLISHED",
  specificContent: {
    "com.linkedin.ugc.ShareContent": {
      shareCommentary: {
        text: "Hello World! This is my first Share on LinkedIn from my organization!",
      },
      shareMediaCategory: "NONE",
    },
  },
  visibility: {
    "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC",
  },
};

axios({
  url: "https://api.linkedin.com/v2/ugcPosts",
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Restli-Protocol-Version": "2.0.0",
    Authorization: "Bearer " + access_token,
  },
  params: params,
})
  .then((response) => {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

I still get the error:

message: "Invalid query parameters passed to request"
serviceErrorCode: 0
status: 400

Do you have any idea to solve my problem?

Source: Ask Javascript Questions

LEAVE A COMMENT