1

When I am trying to upload an image using LinkedIn v2 API every time I get a 400 Bad request error.

Reference is taken from Here : Link

Steps I perform in postman:

Step 1: API: https://api.linkedin.com/v2/assets?action=registerUpload,

Request: POST,

Headers: Authorization: Bearer token, Content-Type: 'application/json', X-Restli-Protocol-Version: '2.0.0'

Request:

{
   "registerUploadRequest":{
      "owner":"urn:li:organization:724981XXX",
      "recipes":[
         "urn:li:digitalmediaRecipe:feedshare-image"
      ],
      "serviceRelationships":[
         {
            "identifier":"urn:li:userGeneratedContent",
            "relationshipType":"OWNER"
         }
      ],
      "supportedUploadMechanism":[
         "SYNCHRONOUS_UPLOAD"
      ]
   }
}

Response: Get uploadUrl

Step2:

End point: uploadURL<from step1's response>,

Request: PUT,

Headers: Authorization: Bearer token, Content-Type: 'image/jpeg', X-Restli-Protocol-Version: '2.0.0', media-type-family:'STILLIMAGE<from step1's response>'

Body: <base_64>

Response: 400 Bad Request

Via curl request working fine. What I am doing wrong?

Thanks in advance.

  • For others who may land here, please notice the `media-type-family` custom header included above. There is a `headers` field returned along with the `uploadUrl` when you register the upload that's not explained in [LinkedIn's guide](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin%2Fconsumer%2Fcontext), but was REQUIRED for me to get the actual upload to work. Without them I got a mystery `400` with no error message. Note these headers are *in addition to* the other required headers (`Authorization`, etc.). – Ross Hunter Jun 09 '22 at 19:36
  • 1
    Apologies for unproductive input, but LinkedIn API is absolute garbage! Am dealing with all these mystery errors, nothing makes sense. Documentation seems to be not updated either. – igsm Jul 27 '22 at 13:32
  • @RossHunter could you please share your code snippet ? also when registering the upload there is no header field, could you provide sample of what you got when registering ? – Bruce_Wayne Oct 19 '22 at 13:03
  • @Bruce_Wayne [here is the full flow](https://gist.github.com/Rossh87/055ae954e6cbce9b6e7b5502301a35c7) I used. Unfortunately the last time I worked on this was several months ago, so I can't guarantee it's the same now. – Ross Hunter Oct 20 '22 at 18:02
  • @RossHunter I got it working already https://stackoverflow.com/a/74143725/1132056, but thanks for responding. I appreciate :) – Bruce_Wayne Oct 21 '22 at 07:31

1 Answers1

4

'Authorization': Bearer ${ access_token },

'X-Restli-Protocol-Version': '2.0.0',

'Content-Type': 'image/jpg'

body is simply the image file contents or a BLOB

method: POST - worked for me... for some PUT worked

Ratan Nahn
  • 90
  • 7
  • I was leaving the json content type header and getting a 400 error with no details. Changing the 'Content-Type' header to the correct type for the image as shown here worked. – dotcomly May 08 '23 at 02:54