Open MaherBTA opened 2 years ago
AFAIK its not implemented yet. I think it invloves a a two step process, upload the file and get an urnID for the same and send those attachments in the request.
POST https://www.linkedin.com/voyager/api/voyagerMediaUploadMetadata?action=upload
{
"mediaUploadType": "MESSAGING_PHOTO_ATTACHMENT",
"fileSize": 5096234,
"filename": "Screenshot 2021-11-06 at 5.26.53 PM.png"
}
This would return a json of the form
{
"data": {
"value": {
"urn": "urn:li:digitalmediaAsset:C5606AQFlP7MTkIqRbA",
"mediaArtifactUrn": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C5606AQFlP7MTkIqRbA,urn:li:digitalmediaMediaArtifactClass:messaging-attachmentFile)",
"recipes": [
"urn:li:digitalmediaRecipe:messaging-attachment"
],
"singleUploadHeaders": {},
"assetRealtimeTopic": "urn:li-realtime:digitalmediaAssetUpdatesTopic:urn:li:digitalmediaAsset:C5606AQFlP7MTkIqRbA",
"singleUploadUrl": "https://www.linkedin.com/dms-uploads/C5606AQFlP7MTkIqRbA/messaging-attachmentFile/0?ca=vector_messaging&cn=uploads_encrypted&f=U2NyZWVuc2hvdCsyMDIxLTExLTA2K2F0KzUuMjYuNTMrUE0ucG5n&sync=1&v=beta&ut=2Xi0Gk6BxBoq41",
"type": "SINGLE",
"$type": "com.linkedin.mediauploader.MediaUploadMetadata"
},
"$type": "com.linkedin.restli.common.ActionResponse"
},
"included": []
}
After this , we need to make a PUT request with data to singleUploadUrl
PUT https://www.linkedin.com/dms-uploads/C5606AQFlP7MTkIqRbA/messaging-attachmentFile/0?ca=vector_messaging&cn=uploads_encrypted&f=U2NyZWVuc2hvdCsyMDIxLTExLTA2K2F0KzUuMjYuNTMrUE0ucG5n&sync=1&v=beta&ut=2Xi0Gk6BxBoq41
After that you could add attachments like below
"attachments": [
{
"id": "urn:li:digitalmediaAsset:C5606AQFlP7MTkIqRbA",
"name": "Screenshot 2021-11-06 at 5.26.53 PM.png",
"byteSize": 5096234,
"mediaType": "image/png",
"reference": {
"string": "blob:https://www.linkedin.com/3bab8027-2344-40ac-8eb9-9fbaa142e3e7"
}
}
]
I am not sure where the "Reference"["string"] is got from. I think it should be the response when the PUT request is successfull.
what should be the payload of the PUT request to singleUploadUrl?
I believe it must be the attachment file. So, the body of the PUT request would contain the binary file.
I get error 400 : bad request when I send a PUT request with a form-data file.
Sorry for the delay in response. I checked again.
The body should be the binary data directly. Dont use form-data. I think it would be something like this https://stackoverflow.com/a/34861614/12306553.
Also it seems, you can omit the "reference": { "string": "blob:https://www.linkedin.com/3bab8027-2344-40ac-8eb9-9fbaa142e3e7" }
while sending the message and it still works.
Big thanks that worked for me!
That's great.🥳 Glad to know it worked.
We'll keep this issue open, incase someone is interested in implementing this functionality in this project.
Hi,
Is there a way to send a message with attachment. I see the attachments field is empty in the payload. what should I put in it ?