Unable to create mail folder using Graph API C#

Mahesh Tibrewal 51 Reputation points
2021-07-22T06:11:00.113+00:00

Using Graph API in C#, we are trying to create a child folder inside Inbox folder for a user's email.

Following is the code snippet for the same:

var newMailFolder = new MailFolder
{
     DisplayName = mailboxName,
     IsHidden = false
};

mailFolder = _gsc.Users[_outlookUser.Id].MailFolders["inbox"].ChildFolders.Request().AddAsync(mailFolder).Result;

This always throws the following exception:

Write requests (excluding DELETE) must contain the Content-Type header declaration

Can someone please help ASAP?

Microsoft Security | Microsoft Graph
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 126.3K Reputation points
    2021-07-22T07:35:09.057+00:00

    Maybe replace AddAsync(mailFolder) with AddAsync(newMailFolder).

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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