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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,015 questions
C#
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.
10,918 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 117.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 Answers by the question author, which helps users to know the answer solved the author's problem.