0

I've used the curl request to upload an image which successfully worked for me.

curl -i --upload-file ~/Desktop/Myimage.jpg -H 'Authorization: Bearer Redacted' "https://api.linkedin.com/mediaUpload/C5522AQHn46pwH96hxQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQLKRJOn_yNw6wAAAW2T0DWnRStny4dzsNVJjlF3aN4-H3ZR9Div77kKoQ&app=1983914&sync=0&v=beta&ut=1Dnjy796bpjEY1"

I've tried using the same request with "request" package which got failed and redirected me to the "404 page not found" LinkedIn page.

Here is the code:

const options = {
            headers: {
                'Authorization': `Bearer ${accessToken}`,
                'X-Restli-Protocol-Version': '2.0.0',
                'Content-Type': 'multipart/form-data'
            },
            method: 'put',
            url: mediaUploadUrl
        }

fs.createReadStream(filePath).pipe(request(options, function(err, httpsResponse, body){
            if ( err ) {
                console.log('err', err);
                response(callback, 400, err);
            } else {
                console.log(body);
                response(callback, 200, { mediaUrn });
            }
        }));

Documentation page that I've followed: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares

#linkedin

1 Answers1

0

The request method is supposed to be POST but you are sending PUT instead, below code should work.

const options = {
        headers: {
            'Authorization': `Bearer ${accessToken}`,
            'X-Restli-Protocol-Version': '2.0.0',
            'Content-Type': 'multipart/form-data'
        },
        method: 'post',
        url: mediaUploadUrl
    }

fs.createReadStream(filePath).pipe(request(options, function(err, httpsResponse, body) {
        if ( err ) {
            console.log('err', err);
            response(callback, 400, err);
        } else {
            console.log(body);
            response(callback, 200, { mediaUrn });
        } 
 }));
Hammed Oyedele
  • 1,030
  • 8
  • 10
  • Thanks. But I've already tried both the method (POST, PUT) and none of them worked for me. Strange thing is that it was working fine before using PUT request. – Swapnil Sharma Jul 11 '20 at 04:56