1

Unable to share image content through share endpoint, image asset is uploaded through assets API but my request to share API which is copied directly from the example here https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?context=linkedin/compliance/context#share-content returns an error, invalid parameters in the request body [/Headers] see below details.

Request Headers:
{Authorization: Bearer ***
X-Restli-Protocol-Version: 2.0.0
}

Request Body
{"content":{"contentEntities":[{"entity":"urn:li:digitalmediaAsset:C5622AQEEn3mmqzCb5w"}],"title":"Great Result","landingPageUrl":"https://google.com.au","shareMediaCategory":"IMAGE"},"distribution":{"linkedInDistributionTarget":{}},"owner":"urn:li:person:zzR_UbXjsG","subject":"Great Result","text":{"text":"Great result, couldn't have gone better #realestate"}}

Scopes:
scope=r_emailaddress w_member_social w_organization_social r_basicprofile rw_company_admin rw_organization_admin

Error:
{"serviceErrorCode":100,"message":"Unpermitted fields present in REQUEST_BODY: Data Processing Exception while processing fields [/Headers]","status":403}
user1846591
  • 61
  • 3
  • 10
  • This error **Occurs when attempting to include an image in an inline comment which is not currently not supported by the API** https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions – Sehdev Mar 24 '20 at 08:26
  • The error message at the link above relates to /content not /headers Unpermitted fields present in REQUEST_BODY: Data Processing Exception while processing fields [/content] Are you saying that there is currently no way to share an image via the API and include a comment with the image, why would the documentation provide an example of an image share with a caption if it's not supported? – user1846591 Mar 26 '20 at 05:03
  • I've removed the comment form the share, same error Unpermitted fields in [/headers] – user1846591 Mar 26 '20 at 05:19

1 Answers1

1

It looks like the error message has to do with the headers. Your request body is JSON, but you don't have a Content-Type header set, so this could be the problem:

Content-Type: application/json

Generally, you need a Content-Length header to be sent along with that, but most of the time the client you are using to send the request handles setting that one.

I'm not sure how you're making the request, but here is a fetch() example in JavaScript (make sure you put the correct auth token in the Authorization header):

const url = 'https://api.linkedin.com/v2/shares';

const requestBody = {
  "content": {
    "contentEntities": [
      {
        "entity": "urn:li:digitalmediaAsset:C5622AQEEn3mmqzCb5w"
      }
    ],
    "title": "Great Result",
    "landingPageUrl": "https://google.com.au",
    "shareMediaCategory": "IMAGE"
  },
  "distribution": {
    "linkedInDistributionTarget": {}
  },
  "owner": "urn:li:person:zzR_UbXjsG",
  "subject": "Great Result",
  "text": {
    "text": "Great result, couldn't have gone better #realestate"
  }
};

async function makeRequest(url, requestBody) {
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ***',
      'X-Restli-Protocol-Version': '2.0.0'
    },
    body: JSON.stringify(requestBody) // body data type must match "Content-Type" header
  });
  return await response.json(); // parses JSON response into native JavaScript objects
}

// make the actual request
makeRequest(url, requestBody);
djs
  • 3,947
  • 3
  • 14
  • 28
  • 1
    I tried adding the content-type no difference, it's strange because all the other calls work without the content-type. {Method: POST, RequestUri: 'https://api.linkedin.com/v2/shares', Version: 1.1, Content: System.Net.Http.ObjectContent`1[System.Net.Http.StringContent], Headers: { Authorization: Bearer ... X-Restli-Protocol-Version: 2.0.0 Accept: application/json Content-Type: application/json; charset=utf-8 Content-Length: 80 }} – user1846591 Mar 30 '20 at 21:33
  • Could the token be expired? That `403` error when trying to use the `/shares` route could be linked to this, from the docs: `Indicates the token used has not been scoped to the correct permissions. Generate a new token with w_organization_social or w_member_social` – djs Mar 30 '20 at 22:00
  • See if [403 access denied](https://learn.microsoft.com/en-us/linkedin/shared/api-guide/concepts/error-handling#403-access-denied) or [refresh access token](https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context#step-5-refresh-access-token) shed some light – djs Mar 30 '20 at 22:09
  • 1
    I just solved it, I was using PostAsJson rather than just PostAs due to a previous issue and request body was being omitted, Fiddler to the rescue. Thanks for your help – user1846591 Mar 30 '20 at 22:16
  • Thanks for sharing. Tried to set ```Content-Type``` to ```application/json```. Still get the same error message as user1846591. Before I had it set to ```application/x-www-form-urlencoded'```. Any idea? [posted the issue here](https://stackoverflow.com/questions/72406550/getting-linkedin-company-shares-python) – Simone May 30 '22 at 08:13