question

AkashSharma-5523 avatar image
0 Votes"
AkashSharma-5523 asked DianaWanjuhi-1579 answered

Graph API Attachment add not working

Encountered something like this working on .Net
While trying to add attachments in Microsoft Graph, using Microsoft Graph Client Library v4.3.0
Able to send mail, get mails , fetch attachments etc

The adding attachment object to a post message
In reply or send mail not working
Tried following these steps as well-
1-Creating a reply (as a draft) endpoint /createReply
2-Adding attachment
3-Sending the mail

In all the above cases the attachment addition is failing with error-

Code- "RequestBodyRead", "message": "The property 'ContentBytes' doesnot exist on type 'microsoft.graph.attachment'.

And ContentBytes is the field supossed to carry the actual attachment as base64.

For attchement types i have tried using
- MessageAttachmentCollectionsPage
- PostAttachmentCollectionsPage
- custom attachment object with only name and contentBytes.

Can anyone guide me regarding this issue.


microsoft-graph-sdkmicrosoft-graph-mail
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DianaWanjuhi-1579 avatar image
0 Votes"
DianaWanjuhi-1579 answered

Hello @AkashSharma-5523 Thank you for reaching out. This is happening because the resource type is wrong, the attachment in this case is of type "@odata.type": "#microsoft.graph.fileAttachment" see documentation here: fileattachment

The microsoft.graph.attachment looks like this: attachment

 {
   "contentType": "string",
   "id": "string (identifier)",
   "isInline": true,
   "lastModifiedDateTime": "String (timestamp)",
   "name": "string",
   "size": 1024
 }

To fix this issue, ensure the type is correct.

Let me know whether this helps, and if you have further questions.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.