Microsoft provides Graph API to interact and work with Office 365 and Microsoft Cloud services. It allows you to create and manage folders, access messages, manage categories and use other services programmatically. In this article, you will learn how to use Microsoft Graph API to create and update folders in Java.
- Java Microsoft Graph API to Manage Folders
- Create Folders using Microsoft Graph API
- Create a Subfolder using Microsoft Graph API
- Update Folders using Microsoft Graph API
Java Microsoft Graph API to Create and Update Folders
To create and update folders using Microsoft Graph API, we will use Aspose.Email for Java. The API makes it quite easier to seamlessly work with Office 365 services using Microsoft Graph API. You can either download the API or install it using the following Maven configurations.
Repository:
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
Dependency:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-email</artifactId>
<version>22.3</version>
<classifier>jdk16</classifier>
</dependency>
Create a Folder with Microsoft Graph API in Java
To communicate with the Graph API, you need to first implement the ITokenProvider interface for authenticating the requests. The following is the basic implementation of ITokenProvider.
The following are the steps to create a folder using Microsoft Graph API in Java.
- First, get an instance of Microsoft Graph client using GraphClient.getClient(ITokenProvider) method.
- Then, call IGraphClient.createFolder(String) method to create the folder.
The following code sample shows how to create a folder using Microsoft Graph API in Java.
Create a Subfolder using Microsoft Graph API in Java
You can also create a subfolder in a similar way. The only difference is that you have to provide the root folder’s path as the first argument of the createFolder method. The following code sample shows how to create a subfolder using Microsoft Graph API in Java.
Java: Update Folders using Microsoft Graph API
You can also fetch and update an existing folder using Microsoft Graph API. For this, you have to get the list of folders and filter the required one. The following are the steps to update a folder using Aspose.Email for Java.
- First, get instance of Microsoft Graph client using GraphClient.getClient(ITokenProvider) method.
- Then, get list of all folders using IGraphClient.listFolders() method.
- After that, loop through all the GraphFolderInfo objects in the list and fetch the required one.
- Then, use GraphFolderInfo object to update the folder’s properties.
- Finally, update the folder using IGraphClient.updateFolder(GraphFolderInfo) method.
The following code sample shows how to update a folder using Microsoft Graph API in Java.
Java Microsoft Graph API to Manage Folders - Get a Free License
You can get a free temporary license to create and update folders with Microsoft Graph API without evaluation limitations.
Conclusion
In this article, you have learned how to work with folders using Microsoft Graph API from within Java applications. Particularly, you have seen how to create or update a folder/subfolder with Microsoft Graph API in Java. Besides, you can explore other features of Aspose.Email for Java using the documentation. Also, in case you would have any questions, you can post to our forum.