Graph API sendMail Java Api - bug? The property 'contentBytes' does not exist on type 'microsoft.graph.attachment'.

Hyland, Keith 5 Reputation points
2023-09-01T12:14:04.7633333+00:00

I am using the sample code to send a mail with a file attachement, and it appears there is a bug in the library.

I'm using graph-java v5.68.0

Sample: [https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=java ](https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=java

)See Example 3 . Create a message with a file attachment and send the message

When i run this I get the error

com.microsoft.graph.http.GraphServiceException: Error code: RequestBodyRead

Error message: The property 'contentBytes' does not exist on type 'microsoft.graph.attachment'. Make sure to only use property names that are defined by the type or mark the type as open type.

POST https://graph.microsoft.com/v1.0/users/******@fmr.com/microsoft.graph.sendMail

SdkVersion : graph-java/v5.68.0

[...]

400 : Bad Request

[...]

It appears to be the same issue as asked here https://learn.microsoft.com/en-us/answers/questions/1355625/graph-api-sendmail-the-property-contentbytes-does

Debugging the code, I see that the oDataType is null for the attachemnt. Hardcoding this value to fileAttachment fixes the issue.

Microsoft Security Microsoft Graph
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Hyland, Keith 5 Reputation points
    2023-09-01T13:17:04.0766667+00:00

    Just add the following line to make it work

    attachments.oDataType = "#microsoft.graph.fileAttachment";


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.