Search code examples
javamicrosoft-graph-api

How to add category code in com.microsoft.graph.models.Message


I am trying to add category code when graphapi reads the mail, for I am trying to use below code.

Message newMessage = new Message();
         newMessage.isRead = true;
         newMessage.importance = Importance.LOW;
         newMessage.categories = no idea how to add categoties!!!
         
         if(shouldFlag) {
             newMessage.flag =  message.flag;
             newMessage.flag.flagStatus = FollowupFlagStatus.FLAGGED;
         }
         
         _appClient.users(o365Mailbox)
             .messages(message.id)
             .buildRequest()
             .patch(newMessage);
    }

Need to know how can I add the category code when graph API reads the mail.


Solution

  • According to the documentation, the type of categories is List<String>.

    You could simply do :

    List<String> msgCategories = new ArrayList<>();
    msgCategories.add("category1");
    msgCategories.add("category2");
    newMessage.categories = msgCategories;
    

    Replace "category1" and "category2" with default categories or with the name of your own custom categories.