Microsoft Graph Add attachment API doesnt work

persistent_test 91 Reputation points
2022-04-15T10:43:59.593+00:00

POST API- https://graph.microsoft.com/v1.0/me/events/AAMkAGI1AAAt9AHjAAA=/attachments

https://learn.microsoft.com/en-us/graph/api/event-post-attachments?view=graph-rest-1.0&tabs=http

{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "menu.txt",
"contentBytes": "base64bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}

Response - Getting 400 error code with below error mesage-
{
"error": {
"code": "UnableToDeserializePostBody",
"message": "were unable to deserialize "
}
}

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,337 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sheena-MSFT 1,731 Reputation points
    2022-04-15T11:27:42.057+00:00

    Hi @persistent_test ,

    You are getting UnableToDeserializePostBody error because in the contentBytes there is base64 appended before the code. Could you please try to remove base64 from the contentBytes?

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

  2. persistent_test 91 Reputation points
    2022-04-18T09:23:53.4+00:00

    Thanks for your reply, I tired by removing "base64", still its not working, getting below error message-

    {
    "error": {
    "code": "ErrorItemNotFound",
    "message": "The specified object was not found in the store.",
    "innerError": {
    "date": "2022-04-18T09:23:01",
    "request-id": "de74783a-e672-443d-bb5a-adecae2429ce",
    "client-request-id": "de74783a-e672-443d-bb5a-adecae2429ce"
    }
    }
    }