Show:      

MSGraphClient

Created by programaths on 17.03.23.
Signature
global with sharing class MSGraphClient

Enums

Name Signature Values
MemberRole
global enum MemberRole
OWNER, GUEST, STANDARD

MSGraphClient Methods

arrayOfCcRecipients(p)

Signature
global static List<CcRecipients> arrayOfCcRecipients(System.JSONParser p)

parseArray(p)

Signature
global static List<Object> parseArray(JSONParser p)

parseChannelList(parser)

Signature
global static List<ChannelData> parseChannelList(JSONParser parser)

parseMap(p)

Signature
global static Map<String,Object> parseMap(JSONParser p)

parseMemberList(parser)

Signature
global static List<Member> parseMemberList(JSONParser parser)

parseSharepointListList(parser)

Signature
global static List<SharePointList> parseSharepointListList(JSONParser parser)

MSGraphClient.AddEntryToListResponse

Signature
global class AddEntryToListResponse

MSGraphClient.AddEntryToListResponse Properties

Name Signature
data
global String data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.AddEntryToListResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.AddMemberData

Signature
global class AddMemberData

MSGraphClient.AddMemberData Properties

Name Signature
displayName
global String displayName
email
global String email
membershipId
global String membershipId
odata_type
global String odata_type
roles
global List<String> roles
userId
global String userId

MSGraphClient.AddMemberData Constructors

AddMemberData(parser)

Signature
global AddMemberData(JSONParser parser)

MSGraphClient.AddMemberResponse

Signature
global class AddMemberResponse

MSGraphClient.AddMemberResponse Properties

Name Signature
data
global Member data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.AddMemberResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.CcRecipients

Signature
global class CcRecipients

MSGraphClient.CcRecipients Properties

Name Signature
emailAddress
global MSGraphClient.EmailAddress emailAddress

MSGraphClient.CcRecipients Constructors

CcRecipients(parser)

Signature
global CcRecipients(JSONParser parser)

MSGraphClient.ChannelData

Signature
global class ChannelData

MSGraphClient.ChannelData Properties

Name Signature
channelId
global String channelId
description
global String description
membershipType
global MembershipType membershipType
name
global String name
teamId
global String teamId

Enums

Name Signature Values
MembershipType
global enum MembershipType
PRIVATE_MEMBERSHIP, STANDARD_MEMBERSHIP, SHARED_MEMBERSHIP

MSGraphClient.ChannelData Constructors

ChannelData()

Signature
global ChannelData()

ChannelData(parser)

Signature
global ChannelData(JSONParser parser)

MSGraphClient.ChannelData Methods

toJson()

Signature
global String toJson()

MSGraphClient.ChannelDataResponse

Signature
global class ChannelDataResponse

MSGraphClient.ChannelDataResponse Properties

Name Signature
data
global ChannelData data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.ChannelDataResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.ChannelResponseData

Signature
global class ChannelResponseData

MSGraphClient.ChannelResponseData Properties

Name Signature
description
global String description
displayName
global String displayName
email
global String email
id
global String id
isFavoriteByDefault
global Boolean isFavoriteByDefault
membershipType
global String membershipType
odata_context
global String odata_context
webUrl
global String webUrl

MSGraphClient.ChannelResponseData Constructors

ChannelResponseData(parser)

Signature
global ChannelResponseData(JSONParser parser)

MSGraphClient.CreateUploadSessionResponse

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class CreateUploadSessionResponse

MSGraphClient.CreateUploadSessionResponse Properties

Name Signature
data
global UploadSession data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.DeleteSharingPermissionResponse

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class DeleteSharingPermissionResponse

MSGraphClient.DeleteSharingPermissionResponse Properties

Name Signature
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.DeleteSharingPermissionResponse Methods

addChannel(userId, channelData)

Add a channel to a Team.
Signature
global ChannelDataResponse addChannel(String userId, ChannelData channelData)
Parameters
userId
Type: String
channelData:
see usage below
Returns
ChannelDataResponse: Object containing the Channel Id or the error. Make sure to save the channelId in Salesforce!
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 //Refresh the Oauth token for the current user or the user you want to use. 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 
 cadmus_una.MSGraphClient.ChannelData cd=new cadmus_una.MSGraphClient.ChannelData(); 
 cd.name='My test Channel'; 
 cd.description='A Channel created from Apex'; 
 cd.teamId='d1bc2d51-6894-4ec2-b0e6-2f09714aaaa4'; //Id retrieves from addTeam call 
 cd.membershipType=cadmus_una.MSGraphClient.MembershipType.PRIVATE_MEMBERSHIP; 
 
 cadmus_una.MSGraphClient.ChannelDataResponse cdr=msGraphClient.addChannel(UserInfo.getUserId(),cd); 
 
 if(cdr.isError()){ 
     System.debug('This is an error'); 
     System.debug(cdr.error); 
 }else{ 
     //Make sure to store the channelId in a field in Salesforce for later reference 
     System.debug('Success with channel Id: '+cdr.data.channelId); 
 } 
 msGraphClient.commitRefreshToken();

addEntryToList(userId, siteId, listId, fields)

Adds a new item to a specific List on a specific Site.
Signature
global AddEntryToListResponse addEntryToList(String userId,String siteId,String listId,Map<String,Object> fields)
Parameters
userId
Type: String
The identifier of the user. This is used for authentication purposes and must be valid.
siteId
The identifier of the site where the list is located. The site must exist and the user must have appropriate permissions.
listId
The identifier of the list where the new item will be added. The list must exist within the specified site.
fields
A Map of fields for the new list item. Each entry in the map represents a field, where the key is the field name and the value is the field value.
Returns
AddEntryToListResponse An instance of the AddEntryToListResponse class. If the operation is successful, the 'error' field of the response will be null, and the 'data' field will contain the Id of the newly created list item. If there was an error (such as an invalid ID, insufficient permissions, etc.), the 'error' field will contain details of the error, and the 'data' field will be null.
Example
cadmus_una.MSGraphClient msGraphClient = new cadmus_una.MSGraphClient(); 
msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
cadmus_una.MSGraphClient.GetSiteResponse getSiteResponse = msGraphClient.getSite(UserInfo.getUserId(), 'https://cloudcrossingautomation.sharepoint.com/sites/COLLABORATIONTEST'); 
 
cadmus_una.MSGraphClient.GetListsFromSiteResponse responsedData = msGraphClient.getListsFromSite(UserInfo.getUserId(), getSiteResponse.data.id); 
 // loop through the list and get the id of the list 
 //	it is best to store the listId in Salesforce 
Map<String,Object> fields = new Map<String,Object>{'Title' => 'My Title', 'FieldName' => 'Value', 'Field2' => DateTime.Now()}; // Replace 'FieldName' and 'Value' with actual field name and value 
cadmus_una.MSGraphClient.AddEntryToListResponse addToResponse = msGraphClient.addEntryToList(UserInfo.getUserId(), getSiteResponse.data.id, 'YourListId', fields); 
System.debug('New Entry Id: ' + addToResponse.data); 
msGraphClient.commitRefreshToken();

addMemberToChannel(userId, teamId, channelId, member)

This method is used to add a member to a channel. The user must be a member of the Team!
Signature
global AddMemberResponse addMemberToChannel(String userId,String teamId,String channelId,Member member)
Parameters
userId:
The ID of the user performing the operation.
teamId:
The ID of the team in which the channel exists.
channelId:
The ID of the channel where the member is to be added.
member:
The Member object containing the details of the member to be added identified via email.
Returns
AddMemberResponse A response object containing the result of the operation.
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 
 cadmus_una.MSGraphClient.Member member=new cadmus_una.MSGraphClient.Member(); 
 member.email='igor.stuyver@pdfbutler.com'; 
 member.role=cadmus_una.MSGraphClient.MemberRole.STANDARD; 
 cadmus_una.MSGraphClient.AddMemberResponse amr=msGraphClient.addMemberToChannel(UserInfo.getUserId(), 
                                                      '60ae6356-a5fe-477f-b88c-4b2dd6a37b86', 
                                                      '19:faea131b8dbd4565bc4a12051c7b9e26@thread.tacv2', 
                                                      member); 
 if(amr.isError()){ 
     System.debug('This is an error'); 
     System.debug(amr.error); 
 }else{ 
     System.debug('Success '+amr.data.membershipId); 
 } 
 msGraphClient.commitRefreshToken();

addMemberToTeam(userId, teamId, member)

This method adds a member to a team.
Signature
global AddMemberResponse addMemberToTeam(String userId,String teamId,Member member)
Parameters
userId:
The ID of the user to be added to the team.
teamId:
The ID of the team where the user is to be added.
member:
The member to add, identified by email address.
Returns
AddMemberResponse A response object containing the result of the operation.
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 
 cadmus_una.MSGraphClient.Member member=new cadmus_una.MSGraphClient.Member(); 
 member.email='igor.stuyver@pdfbutler.com'; 
 member.role=cadmus_una.MSGraphClient.MemberRole.STANDARD; 
 cadmus_una.MSGraphClient.AddMemberResponse amr=msGraphClient.addMemberToTeam(UserInfo.getUserId(), 
                                                                    '60ae6356-a5fe-477f-b88c-4b2dd6a37b86', 
                                                                    member); 
 if(amr.isError()){ 
     System.debug('This is an error'); 
     System.debug(amr.error); 
 }else{ 
     System.debug('Success '+amr.data.membershipId); 
 } 
 msGraphClient.commitRefreshToken();

addTeam(userId, teamData)

This method is used to add a new team. According to O365 documentation, the creation of a team can take between 0 seconds and 5 minutes!
Signature
global TeamDataResponse addTeam(String userId,TeamData teamData)
Parameters
userId:
Id of the Salesforce user you want to use to generate the team with.
TeamData:
Information required for the team to be generated
Returns
AddTeamResponse An object containing the result of the operation. Make sure to store the teamId in a field in Salesforce for later reference
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 //Refresh the Oauth token for the current user or the user you want to use. 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 
 cadmus_una.MSGraphClient.TeamData td=new cadmus_una.MSGraphClient.TeamData(); 
 td.name='My test team 3'; 
 td.description='A team created from Apex double check'; 
 
 cadmus_una.MSGraphClient.TeamDataResponse tdr=msGraphClient.addTeam(UserInfo.getUserId(),td); 
 
 if(tdr.isError()){ 
     System.debug('This is an error'); 
     System.debug(tdr.error); 
 }else{ 
     //Make sure to store the teamId in a field in Salesforce for later reference 
     System.debug('Success with team Id: '+tdr.data.teamId); 
 } 
 msGraphClient.commitRefreshToken();
Signature
global CollabMSGraphClient.CreateLinkResponse cadmus_una_createSharingLink(String userId, String driveId, String itemId)

commitRefreshToken()

Call this method after calling multiple methods on the SharePoint API, just to make sure the credentials are updated and this action has to happens once for all API calls.
Signature
global void commitRefreshToken()
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.commitRefreshToken();

createChatMessage(userId, channelName, htmlMessage)

Signature
global CollabMSGraphClient.CreateChatMessageResponse createChatMessage(String userId,String channelName,String htmlMessage)
Parameters
userId
Type: String
UserId or empty for "current user"
channelName
Channel name
htmlMessage
Message in HTML
Returns
Completion status
Example
 // Send "html message" on "channel topic" using current sfdc user. 
 cadmus_una.CollabMSGraphClient.createChatMessage(null,'channel topic','html message');

createChatMessageWithQueue(userId, channelName, htmlMessage, queueable)

Signature
global CollabMSGraphClient.CreateChatMessageResponse createChatMessageWithQueue(String userId,String channelName,String htmlMessage,List<Queueable> queueable)

createDraftEmail(userId, emailMessage)

Create a draft email.
Signature
global CollabMSGraphClient.CreateDraftEmailResponse createDraftEmail(String userId,Messaging.SingleEmailMessage emailMessage)
Parameters
userId
Type: String
User Id to euthenticate with
emailMessage
Email message to be saved in drafts
Returns
Draft Id.

createFolder(userId, driveId, parentId, name)

Create folder "name" in drive identified by "driveId" with parent identified by "parentId"
Signature
global CollabMSGraphClient.SaveFileResponse createFolder(String userId, String driveId, String parentId, String name)
Parameters
userId
Type: String
user ID
driveId
Type: String
drive ID
parentId
Type: String
parent ID
name
Type: String
folder name
Returns
created folder
Example
  //For Unit Testing, make sure tho init the client like below 
  MSGraphClient client; 
   if(Test.isRunningTest()){ 
       client=MSGraphClient.createMock(new MSGraphClient.MSGraphClientStub()); 
   }else{ 
       client=new MSGraphClient(); 
   } 
 //the client is now initiated for Unit Testing or general execution. The rest of the calls can be the same for Unit Testing or general execution. 
 //   below and example of a call 
 
 String libraryUrl = 'https://company.sharepoint.com/sites/MySiteName'; 
 cadmus_una.CollabMSGraphClient.GetDriveResponse dr=cadmus_una.CollabMSGraphClient.getSiteDrive(UserInfo.getUserId(), 
      'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten'); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse di=cadmus_una.CollabMSGraphClient.getDriveItemByPath(UserInfo.getUserId(), dr.data.id, '/General'); 
 cadmus_una.MSGraphClient.SaveFileResponse fileResponse = client.createFolder(UserInfo.getUserId(), dr.data.id, di.data.id, '/MyCoolFolder');

createMock(stubProvider)

the unit test stub which implements the mock methods
Signature
global static MSGraphClient createMock(StubProvider stubProvider)
Parameters
stubProvider
Type: StubProvider
use the default Stub from COLLABORATION Butler "new MSGraphClient.MSGraphClientStub()". Or create your own Stub for each method you want to use.
Returns
Mock
Example
  MSGraphClient client; 
   if(Test.isRunningTest()){ 
       client=MSGraphClient.createMock(new MSGraphClient.MSGraphClientStub()); 
   }else{ 
       client=new MSGraphClient(); 
   } 
 //the client is now initiated for Unit Testing or general execution. The rest of the calls can be the same for Unit Testing or general execution. 
 //   below and example of a call 
 
 String libraryUrl = 'https://company.sharepoint.com/sites/MySiteName'; 
 cadmus_una.MSGraphClient.GetDriveResponse driveResponse = client.getSiteDrive(UserInfo.getUserId(), libraryUrl);
Creates a sharing link for a specific item stored in a drive. This global method acts as a wrapper or proxy that facilitates the interaction with the Microsoft Graph API through the 'CollabMSGraphClient' class. By providing the necessary identifiers, users can generate a link that allows for sharing access to a file or folder located within a specified drive.
Signature
global CollabMSGraphClient.CreateLinkResponse createSharingLink(String userId, String driveId, String itemId)
Parameters
userId
Type: String
The unique identifier of the user on behalf of whom the operation is performed. The method uses this ID to authenticate and authorize the request, ensuring the user has the necessary permissions to create a sharing link for the item.
driveId
Type: String
The unique identifier of the drive within which the item resides. This ID helps in locating the drive in the system and identifying the item that needs to be shared.
itemId
Type: String
The unique identifier of the item (file or folder) for which the sharing link is created. This ID is crucial in pinpointing the exact item in the drive.
Returns
A 'CreateLinkResponse' object that contains the response from the 'createSharingLink' method of the 'CollabMSGraphClient'. It includes details such as the sharing link itself, any permissions associated with the link, and other relevant metadata regarding the sharing operation.
Example
  cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
  msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
  cadmus_una.CollabMSGraphClient.GetDriveResponse fr= msGraphClient.getSiteDrive(UserInfo.getUserId(), 'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten'); 
  cadmus_una.CollabMSGraphClient.GetDriveResponse di=msGraphClient.getDriveItemByPath(UserInfo.getUserId(),fr.data.id,'/share-test/a/3-user-sharing'); 
  cadmus_una.MSGraphClient.GetSharingPermissionsResponse spr=msGraphClient.getSharingPermissions(UserInfo.getUserId(),di.data); 
  System.debug(spr.data); 
  msGraphClient.commitRefreshToken(); 
  cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
  CollabMSGraphClient.CreateLinkResponse response = msGraphClient.createSharingLink(UserInfo.getUserId(), fr.id, di.id); 
  System.debug('Sharing Link: ' + response.link);
@return
Signature
@Deprecated
global CollabMSGraphClient.CreateLinkResponse createSharingLink(String userId,String siteDrive,Datetime expiry,List<String> userEmails,CollabMSGraphClient.ShareAccessType accessType)
Parameters
userId
Type: String
siteDrive
expiry
userEmails
accessType
Create a sharing link in SharePoint @return
Signature
global CollabMSGraphClient.CreateLinkResponse createSharingLink(String userId, String driveId, String itemId,Datetime expiryDate,List<String> userEmails,CollabMSGraphClient.ShareAccessType accessType)
Parameters
userId
Type: String
user to create sharing link with
driveId
Type: String
See example on how to retrive the Drive Id
itemId
Type: String
See example on how to retrive the item Id, this can be a file or folder
expiryDate
DateTime 24 hours in the future, ignored when sharing is not anonymous or Site does not allow to share with anonymous
userEmails
list of email addresses to share with. Leave empty when anonymous.
accessType
View are edit
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse dr=msGraphClient.getSiteDrive(UserInfo.getUserId(), 
          'https://cloudcrossingautomation.sharepoint.com/sites/Site-With-Dashes/Shared Documents'); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse di=msGraphClient.getDriveItemByPath(UserInfo.getUserId(), 
          dr.data.id, 'ok/Test2.docx'); 
 if(di.isError()) { 
     System.debug(LoggingLevel.ERROR, di.error); 
 } else { 
     CollabMSGraphClient.CreateLinkResponse resp = msGraphClient.createSharingLink(UserInfo.getUserId(),dr.data.id,di.data.id, 
                              Datetime.now().addDays(7), 
                              new List<String>{'person.xyz@pdfbutler.com'}, 
                              CollabMSGraphClient.ShareAccessType.EDIT); 
     if(resp.isError()) { 
         System.debug(LoggingLevel.ERROR, resp.error); 
     } else { 
     	System.debug('Sharing link: ' + resp.data.link.webUrl); 
     } 
 } 
 msGraphClient.commitRefreshToken();
Create a sharing link in SharePoint @return
Signature
global CollabMSGraphClient.CreateLinkResponse createSharingLink(String userId, String driveId, String itemId,Datetime expiryDate,List<String> userEmails)
Parameters
userId
Type: String
user to create sharing link with
driveId
Type: String
See example on how to retrive the Drive Id
itemId
Type: String
See example on how to retrive the item Id, this can be a file or folder
expiryDate
DateTime 24 hours in the future, ignored when sharing is not anonymous or Site does not allow to share with anonymous
userEmails
list of email addresses to share with. Leave empty when anonymous.
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse dr=msGraphClient.getSiteDrive(UserInfo.getUserId(), 
          'https://cloudcrossingautomation.sharepoint.com/sites/Site-With-Dashes/Shared Documents'); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse di=msGraphClient.getDriveItemByPath(UserInfo.getUserId(), 
          dr.data.id, 'ok/Test2.docx'); 
 if(di.isError()) { 
     System.debug(LoggingLevel.ERROR, di.error); 
 } else { 
     CollabMSGraphClient.CreateLinkResponse resp = msGraphClient.createSharingLink(UserInfo.getUserId(),dr.data.id,di.data.id, 
                              Datetime.now().addDays(7), 
                              new List<String>{'person.xyz@pdfbutler.com'}); 
     if(resp.isError()) { 
         System.debug(LoggingLevel.ERROR, resp.error); 
     } else { 
     	System.debug('Sharing link: ' + resp.data.link.webUrl); 
     } 
 } 
 msGraphClient.commitRefreshToken();

createSharingLinkFromLibraryAndPath(userId, libraryUrl, path, expiryDate, userEmails, accessType)

Signature
global CollabMSGraphClient.CreateLinkResponse createSharingLinkFromLibraryAndPath(String userId, String libraryUrl, String path,Datetime expiryDate,List<String> userEmails,CollabMSGraphClient.ShareAccessType accessType)

createUploadSession(userId, driveId, parentItemId, fileName)

Signature
global CreateUploadSessionResponse createUploadSession(String userId,String driveId,String parentItemId,String fileName)

deleteSharingPermission(userId, sharingLink)

@return
Signature
global DeleteSharingPermissionResponse deleteSharingPermission(String userId,String sharingLink)
Parameters
userId
Type: String
sharingLink
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.MSGraphClient.DeleteSharingPermissionResponse perms=msGraphClient.deleteSharingPermission(UserInfo.getUserId(), 
     'https://cloudcrossingautomation.sharepoint.com/:i:/s/COLLABORATIONTEST/testsubsite/EeOasxB7PvFDmuS7jJSh4toBT6LPRHuCJAuBGp0z6KKghg'); 
 if(perms.isError()) { 
     System.debug(LoggingLevel.ERROR, perms.error); 
 } 
 msGraphClient.commitRefreshToken();

deleteSharingPermissionsByEmail(userId, item, email)

Removes sharing permissions for a specific email on a Microsoft Graph Drive Item. This method iterates over all the sharing permissions of a given item and deletes the permissions associated with the specified email address.
Signature
global DeleteSharingPermissionResponse deleteSharingPermissionsByEmail(String userId,CollabMSGraphClient.GetDriveResponseData item,String email)
Parameters
userId
Type: String
The user ID for which the operation is performed. If blank, it defaults to the current user's ID.
item
The drive item for which permissions need to be modified, encapsulated in a GetDriveResponseData object.
email
The email address for which the sharing permissions will be deleted.
Returns
DeleteSharingPermissionResponse This response object includes details about the operation's success or failure.
Example
 cadmus_una.MSGraphClient client; 
 if(Test.isRunningTest()){ 
      client= cadmus_una.MSGraphClient.createMock(new cadmus_una.MSGraphClient.MSGraphClientStub()); 
  }else{ 
      client=new cadmus_una.MSGraphClient(); 
  } 
  client.prepareRefreshToken(UserInfo.getUserId()); 
  String userId = UserInfo.getUserId(); 
  MSGraphClient client; 
  if(Test.isRunningTest()){ 
      client=cadmus_una.MSGraphClient.createMock(new MSGraphClient.MSGraphClientStub()); 
  }else{ 
      client=new cadmus_una.MSGraphClient(); 
  } 
  client.prepareRefreshToken(UserInfo.getUserId()); 
  String userId = UserInfo.getUserId(); 
 
  // Get the drive item first 
  cadmus_una.CollabMSGraphClient.GetDriveResponse driveResponse = client.getSiteDrive(userId, 'https://cloudcrossingautomation.sharepoint.com/sites/YourSite/Your Library'); 
  cadmus_una.CollabMSGraphClient.GetDriveResponse itemResponse = client.getDriveItemByPath(userId, driveResponse.data.id, '/Path/To/Folder'); 
 
  // Delete sharing permissions for a specific email 
  String email = 'your.email@pdfbutler.com'; 
  cadmus_una.MSGraphClient.DeleteSharingPermissionResponse response = client.deleteSharingPermissionsByEmail(userId, itemResponse.data, email); 
 
  if (response.isError()) { 
      System.debug('Error: ' + response.error); 
  } else { 
      System.debug('Sharing permissions deleted successfully for email: ' + email); 
  } 
  client.commitRefreshToken();

ensurePath(userId, driveId, path)

Ensures that the given path exists in the specified drive. If any folder in the path doesn't exist, this method attempts to create it.
Signature
global Boolean ensurePath(String userId, String driveId, String path)
Parameters
userId
Type: String
The user ID for which the path should be ensured.
driveId
Type: String
The drive ID in which the path should be ensured.
path
Type: String
The path to be ensured, with each folder separated by a forward slash (/).
Returns
true if the path exists or has been successfully created, false otherwise.
Example
 String userId = "user123"; 
 String driveId = "drive123"; 
 String path = "Projects/MyProject/SubFolder"; 
 
 Boolean result = cadmus_una.MSGraphClient.ensurePath(userId, driveId, path); 
 if (result) { 
     System.out.println("Path ensured: " + path); 
 } else { 
     System.out.println("Failed to ensure path: " + path); 
 }

getDrive(userId, siteUrl)

Get drive from URL. You probably do not want to use this. #getSiteDrive()
Signature
global CollabMSGraphClient.GetDriveResponse getDrive(String userId, String siteUrl)
Parameters
userId
Type: String
user Id
siteUrl
Type: String
site URL
Returns
corresponding drive
See
CollabMSGraphClient.getSiteDrive()

getDriveItemByPath(userId, driveId, path)

Retrieve drive item in drive "driveId" at path <var>path</var>
Signature
global CollabMSGraphClient.GetDriveResponse getDriveItemByPath(String userId, String driveId, String path)
Parameters
userId
Type: String
User Id
driveId
Type: String
drive ID
path
Type: String
path
Returns
drive item at path <var>path</var>. See: GetDriveResponse
Example
  void listChildren(String driveId,String childId,Integer level){ 
        cadmus_una.MSGraphClient.GetDriveContentResponse contentResponse=cadmus_una.MSGraphClient.getDriveItemsById( 
            UserInfo.getUserId(),driveId,childId); 
        for(cadmus_una.MsGraphContentResponse.Value v: contentResponse.data.value){ 
            System.debug(LoggingLevel.DEBUG,'-'.repeat(level)+v.name+'('+((v.folder==null)?'file':v.folder.childCount+')')); 
            System.debug(LoggingLevel.DEBUG,v.folder); 
            if(v.folder!=null){ 
                listChildren(driveId,v.id,level+1); 
            } 
        } 
    } 
    cadmus_una.MSGraphClient.GetDriveResponse dr=cadmus_una.MSGraphClient.getSiteDrive(UserInfo.getUserId(), 
            'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten'); 
    cadmus_una.MSGraphClient.GetDriveResponse di=cadmus_una.MSGraphClient.getDriveItemByPath(UserInfo.getUserId(), dr.data.id, '/General'); 
    listChildren(dr.data.id,di.data.id,0);

getDriveItemsById(userId, driveId, childId)

Signature
global CollabMSGraphClient.GetDriveContentResponse getDriveItemsById(String userId, String driveId, String childId)

getDriveItemsByPath(userId, driveId, path)

Retrieve drive items (children) in drive "driveId" at path <var>path</var>
Signature
global CollabMSGraphClient.GetDriveContentResponse getDriveItemsByPath(String userId, String driveId, String path)
Parameters
userId
Type: String
User Id
driveId
Type: String
drive ID
path
Type: String
path
Returns
drive items (children) at path <var>path</var>. See: GetDriveContentResponse
See
CollabMSGraphClient.getDriveItemByPath to get the item itself
Example
 String userId = "user123"; 
  String driveId = "drive123"; 
  String path = "Documents/Reports"; 
 
  cadmus_una.CollabMSGraphClient.GetDriveContentResponse response = cadmus_una.CollabMSGraphClient.getDriveItemsByPath(userId, driveId, path); 
 
  if (response.error != null) { 
      System.out.println("Error code: " + response.error.code); 
      System.out.println("Error message: " + response.error.message); 
  } else { 
      System.out.println("Drive content: " + response.data); 
  }

getDriveItemsByPathFiltered(userId, driveId, path, wildcard)

Fetches and filters DriveItems from a specific path in a user's Drive. The glob pattern rules are: - '*' matches any string of characters - '?' matches any single character
Signature
global CollabMSGraphClient.GetDriveContentResponse getDriveItemsByPathFiltered(String userId, String driveId, String path,String wildcard)
Parameters
userId
Type: String
A String representing the unique identifier of a User.
driveId
Type: String
A String representing the unique identifier of a Drive.
path
Type: String
A String representing the path in the Drive where items are located.
wildcard
A String which is a glob pattern, used for filtering DriveItems based on their names.
Returns
Returns a GetDriveContentResponse object, which contains the list of filtered DriveItems. If there's an error during the request, the GetDriveContentResponse will contain the error details.
Example
 // This will return all files starting with 'bar' and the extension starting with 'p', from the given path in the Drive for the current user. 
 MSGraphClient cli=new MSGraphClient(); 
 cli.prepareRefreshToken(UserInfo.getUserId()); 
 CollabMSGraphClient.GetDriveResponse gdr=cli.getSiteDrive(UserInfo.getUserId(),'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten'); 
 CollabMSGraphClient.GetDriveContentResponse gdcr=cli.getDriveItemsByPathFiltered(UserInfo.getUserId(),gdr.data.id,'Accounts/Dickenson plc2', 'bar*.p*'); 
 
 for (MsGraphContentResponse.Value value : gdcr.data.value) { 
     System.debug(value.name); 
 } 
 cli.commitRefreshToken();

getEntryFromList(userId, siteId, listId, itemId)

Retrieves a specific item from a specified list on a specific site.
Signature
global GetEntryFromListResponse getEntryFromList(String userId,String siteId,String listId,String itemId)
Parameters
userId
Type: String
The identifier of the user. This is used for authentication purposes and must be valid.
siteId
The identifier of the site where the list is located. The site must exist and the user must have appropriate permissions.
listId
The identifier of the list from where the item will be fetched. The list must exist within the specified site.
itemId
The identifier of the item to be retrieved from the list.
Returns
GetEntryFromListResponse An instance of the GetEntryFromListResponse class. If the operation is successful, the 'error' field of the response will be null, and the 'data' field will contain the details of the list item requested. If there was an error (such as an invalid list Item Id, insufficient permissions, etc.), the 'error' field will contain details of the error, and the 'data' field will be null.
Example
 cadmus_una.MSGraphClient msGraphClient = new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.MSGraphClient.GetEntryFromListResponse getResponse = msGraphClient.getEntryFromList(UserInfo.getUserId(), 'YourSiteId', 'YourListId', 'YourItemId'); 
 System.debug('Get Entry Response: ' + getResponse.data); 
 System.debug('Get Entry id: ' + getResponse.data.id); 
 System.debug('Get Entry Title: ' + getResponse.data.fields.get('Title')); 
 msGraphClient.commitRefreshToken();

getFile(userId, url, isLibrary, path)

Gets a SharePoint file
Signature
global CollabMSGraphClient.GetFileResponse getFile(String userId, String url, Boolean isLibrary, String path)
Parameters
userId
Type: String
the user of which the SharePoint credentials should be used. Current user: UserInfo.getUserId()
url
Type: String
Site Library Url
isLibrary
Type: Boolean
unless you are using an old version, use "true"
path
Type: String
sharepoint library folder patch
Returns
GetFileResponse object
Example
 cadmus_una.MSGraphClient client=new cadmus_una.MSGraphClient(); 
 client.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.CollabMSGraphClient.GetFileResponse resp = client.getFile(UserInfo.getUserId(), 
               'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten', 
               true, '/General/Test Corelus.docx'); 
 System.debug('resp: ' + resp); 
 if(resp.isError()) { 
     System.debug(LoggingLevel.ERROR, resp.error + ': ' + resp.error); 
 } else { 
 	System.debug('blob: ' + resp.data); 
 } 
 client.commitRefreshToken();

getFileAsPDF(userId, url, isLibrary, path)

Converts a SharePoint file into PDF - Remote Site Setting: https://westeurope1-mediap.svc.ms
Signature
global CollabMSGraphClient.GetFileResponse getFileAsPDF(String userId, String url, Boolean isLibrary, String path)
Parameters
userId
Type: String
the user of which the SharePoint credentials should be used. Current user: UserInfo.getUserId()
url
Type: String
Site Library Url
isLibrary
Type: Boolean
unless you are using an old version, use "true"
path
Type: String
sharepoint library folder patch
Returns
GetFileResponse object
Example
 cadmus_una.CollabMSGraphClient.getFileAsPDF(UserInfo.getUserId(), 'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten', 
 true, '/General/Test Corelus.docx'); => the blob is on “response.data”

getListsFromSite(userId, siteId)

Retrieves the lists from a specified site.
Signature
global GetListsFromSiteResponse getListsFromSite(String userId,String siteId)
Parameters
userId
Type: String
The identifier of the user. This is used for authentication purposes and must be valid.
siteId
The identifier of the site where the lists will be retrieved from. The site must exist and the user must have the appropriate permissions.
Returns
GetListsFromSiteResponse An instance of the GetListsFromSiteResponse class. If the operation is successful, the 'error' field of the response will be null, and the 'data' field will contain the lists retrieved from the site. If there was an error during the retrieve operation (such as an invalid site Id, insufficient permissions, etc.), the 'error' field will contain details of the error, and the 'data' field will be null.
Example
 cadmus_una.MSGraphClient msGraphClient = new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.MSGraphClient.GetSiteResponse getSiteResponse = msGraphClient.getSite(UserInfo.getUserId(), 'https://cloudcrossingautomation.sharepoint.com/sites/COLLABORATIONTEST'); 
 
 cadmus_una.MSGraphClient.GetListsFromSiteResponse responsedData = msGraphClient.getListsFromSite(UserInfo.getUserId(), getSiteResponse.data.id); 
 //-- if sucessfully executed 'responsedData.data' will holds the returned lists, and 'err.message' will be null. 
 //-- if error occurred during the operation 'err.message' will hold error message and 'responsedData.data' will be null. 
 System.debug('Result: ' + responsedData.data); 
 for(cadmus_una.MSGraphClient.SharePointList item : responsedData.data) { 
 	   System.debug('id: ' + item.id); 
     System.debug('name: ' + item.name); 
     System.debug('createdDateTime: ' + item.createdDateTime); 
     System.debug('lastModifiedDateTime: ' + item.lastModifiedDateTime); 
 } 
 msGraphClient.commitRefreshToken();

getRefreshedToken(userId)

Signature
global String getRefreshedToken(String userId)

getSharingPermission(userId, sharingLink)

Signature
global GetSharingPermissionResponse getSharingPermission(String userId,String sharingLink)
Parameters
userId
Type: String
sharingLink
Returns
sharing link permission
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.MSGraphClient.GetSharingPermissionResponse perms=msGraphClient.getSharingPermission(UserInfo.getUserId(), 
    'https://cloudcrossingautomation.sharepoint.com/:i:/s/COLLABORATIONTEST/testsubsite/EeOasxB7PvFDmuS7jJSh4toBT6LPRHuCJAuBGp0z6KKghg'); 
 msGraphClient.commitRefreshToken();

getSharingPermissions(userId, itemId)

@return
Signature
global GetSharingPermissionsResponse getSharingPermissions(String userId,CollabMSGraphClient.GetDriveResponseData itemId)
Parameters
userId
Type: String
itemId
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse fr= msGraphClient.getSiteDrive(UserInfo.getUserId(), 'https://cloudcrossingautomation.sharepoint.com/sites/Marketing21/Gedeelde documenten'); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse di=msGraphClient.getDriveItemByPath(UserInfo.getUserId(),fr.data.id,'/share-test/a/3-user-sharing'); 
 cadmus_una.MSGraphClient.GetSharingPermissionsResponse spr=msGraphClient.getSharingPermissions(UserInfo.getUserId(),di.data); 
 System.debug(spr.data); 
 msGraphClient.commitRefreshToken();

getSite(userId, siteUrl)

Retrieves the site information by given URL.
Signature
global GetSiteResponse getSite(String userId,String siteUrl)
Parameters
userId
Type: String
The identifier of the user. This is used for authentication purposes and must be valid.
siteUrl
The URL of the site to be retrieved. The site must exist and the user must have appropriate permissions.
Returns
GetSiteResponse An instance of the GetSiteResponse class. If the operation is successful, the 'error' field of the response will be null. If there was an error during the retrieval operation (such as an invalid Site URL, insufficient permissions, etc.), the 'error' field will contain details of the error.
Example
 cadmus_una.MSGraphClient msGraphClient = new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
cadmus_una.MSGraphClient.GetSiteResponse getSiteResponse = msGraphClient.getSite(UserInfo.getUserId(), 'https://cloudcrossingautomation.sharepoint.com/sites/COLLABORATIONTEST'); 
System.debug('displayName: ' + getSiteResponse.data.displayName); 
System.debug('id: ' + getSiteResponse.data.id); 
System.debug('name: ' + getSiteResponse.data.name); 
System.debug('createdDateTime: ' + getSiteResponse.data.createdDateTime); 
System.debug('lastModifiedDateTime: ' + getSiteResponse.data.lastModifiedDateTime); 
 msGraphClient.commitRefreshToken();

getSiteDrive(userId, libraryUrl)

Get drive from URL, tacking into account sites and libraries.
Signature
global CollabMSGraphClient.GetDriveResponse getSiteDrive(String userId, String libraryUrl)
Parameters
userId
Type: String
user Id
libraryUrl
Type: String
site/library URL
Returns
corresponding drive: GetDriveResponse
Example
 String userId = '0051N0000017s9sQAA'; 
 String libraryUrl = 'https://company.sharepoint.com/sites/MySiteName'; 
 cadmus_una.MSGraphClient client=new cadmus_una.MSGraphClient(); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse driveResponse = client.getSiteDrive(userId, libraryUrl); 
 
 if (driveResponse.data != null) { 
     System.debug('Drive ID: ' + driveResponse.data.id); 
 } else { 
     System.debug('Error: ' + driveResponse.error.message); 
 }

grantSharingLinkAccess(userId, sharingLink, userEmails)

Create a sharing link in SharePoint @return
Signature
global CollabMSGraphClient.GrantSharingLinkResponse grantSharingLinkAccess(String userId,String sharingLink,List<String> userEmails)
Parameters
userId
Type: String
user to create sharing link with
sharingLink
Link you get after creating a sharing
userEmails
list of email addresses to share with. Leave empty when anonymous.
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse dr=msGraphClient.getSiteDrive(UserInfo.getUserId(), 
          'https://cloudcrossingautomation.sharepoint.com/sites/Site-With-Dashes/Shared Documents'); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse di=msGraphClient.getDriveItemByPath(UserInfo.getUserId(), 
          dr.data.id, 'ok/Test2.docx'); 
 if(di.isError()) { 
     System.debug(LoggingLevel.ERROR, di.error); 
 } else { 
     cadmus_una.CollabMSGraphClient.CreateLinkResponse resp = msGraphClient.grantSharingLinkAccess(UserInfo.getUserId(),'u!xxxx', 
                              new List<String>{'person.xyz@pdfbutler.com'}); 
     if(resp.isError()) { 
         System.debug(LoggingLevel.ERROR, resp.error); 
     } else { 
     	System.debug('Sharing link: ' + resp.data.link.webUrl); 
     } 
 } 
 msGraphClient.commitRefreshToken();

grantSharingLinkAccess(userId, sharingLink, userEmails, accessType)

Create a sharing link in SharePoint @return
Signature
global CollabMSGraphClient.GrantSharingLinkResponse grantSharingLinkAccess(String userId,String sharingLink,List<String> userEmails,CollabMSGraphClient.ShareAccessType accessType)
Parameters
userId
Type: String
user to create sharing link with
sharingLink
Link you get after creating a sharing
userEmails
list of email addresses to share with. Leave empty when anonymous.
accessType
the access type
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse dr=msGraphClient.getSiteDrive(UserInfo.getUserId(), 
          'https://cloudcrossingautomation.sharepoint.com/sites/Site-With-Dashes/Shared Documents'); 
 cadmus_una.CollabMSGraphClient.GetDriveResponse di=msGraphClient.getDriveItemByPath(UserInfo.getUserId(), 
          dr.data.id, 'ok/Test2.docx'); 
 if(di.isError()) { 
     System.debug(LoggingLevel.ERROR, di.error); 
 } else { 
     cadmus_una.CollabMSGraphClient.CreateLinkResponse resp = msGraphClient.grantSharingLinkAccess(UserInfo.getUserId(),'u!xxxx', 
                              new List<String>{'person.xyz@pdfbutler.com'},cadmus_una.CollabMSGraphClient.ShareAccessType.VIEW); 
     if(resp.isError()) { 
         System.debug(LoggingLevel.ERROR, resp.error); 
     } else { 
     	System.debug('Sharing link: ' + resp.data.link.webUrl); 
     } 
 } 
 msGraphClient.commitRefreshToken();

inviteGuest(userId, inviteRedirectUrl, member)

Invite Guest user to O365
Signature
global InviteGuestResponse inviteGuest(String userId,String inviteRedirectUrl,Member member)
Parameters
userId
Type: String
inviteRedirectUrl
member
Returns
InviteGuestResponse: will have the O365 userId of the invited guest. Best this id is stored on the User SObject in SFDC.
Example
 cadmus_una.MSGraphClient msGraphClient =new MSGraphClient(); 
  msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
  cadmus_una.MSGraphClient.Member m=new cadmus_una.MSGraphClient.Member(); 
  m.email='programaths@gmail.com'; 
  cadmus_una.MSGraphClient.InviteGuestResponse tdr=msGraphClient.inviteGuest(UserInfo.getUserId(),'http://www.pdfbutler.com',m); 
  System.debug('O365 user Id: ' + tdr.data.userId); 
  msGraphClient.commitRefreshToken();

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

isSubsite(domain, siteName, possibleSubSiteName, token)

Signature
global Boolean isSubsite(String domain,String siteName,String possibleSubSiteName,String token)
Parameters
domain
Type: String
Sharepoint domain
siteName
Sharepoint site
possibleSubSiteName
Sharepoint subsite
token
Sharepoint auth token
Returns
Whether <var>possibleSubSiteName</var> is a sub site of <var>siteName</var> for domain <var>domain</var>
See
CollabOAuthController.getSavedToken

isTokenValid(userId)

Signature
global Boolean isTokenValid(String userId)

listTeamChannelMembers(userId, teamId, channelId)

List all members for a channel
Signature
global ListMembersResponse listTeamChannelMembers(String userId,String teamId,String channelId)
Parameters
userId
Type: String
teamId
channelId
Returns
ListMembersResponse
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.MSGraphClient.ListMembersResponse lm=msGraphClient.listTeamChannelMembers(UserInfo.getUserId(), 
 											'60ae6356-a5fe-477f-b88c-4b2dd6a37b86', 
 											'19:faea131b8dbd4565bc4a12051c7b9e26@thread.tacv2'); 
 if(lm.isError()){ 
     System.debug('This is an error'); 
     System.debug(lm.error.message); 
 }else{ 
     System.debug('Success '+lm.data.size()); 
     for(cadmus_una.MSGraphClient.Member member : lm.data) { 
         System.debug('member id: '+member.membershipId); 
         System.debug('member email: '+member.email); 
         System.debug('member role: '+member.role); 
         System.debug('member userId: '+member.userId); 
         System.debug('member displayName: '+member.displayName); 
     } 
 } 
 msGraphClient.commitRefreshToken();

listTeamChannels(userId, teamId)

List all channels linked to a Team @return
Signature
global ListTeamChannelsResponse listTeamChannels(String userId,String teamId)
Parameters
userId
Type: String
teamId
Example
  cadmus_una.MSGraphClient msGraphClient =new MSGraphClient(); 
  msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
  cadmus_una.MSGraphClient.ListTeamChannelsResponse ltcr=msGraphClient.listTeamChannels(UserInfo.getUserId(),'60ae6356-a5fe-477f-b88c-4b2dd6a37b86'); 
  if(ltcr.isError()){ 
      System.debug('This is an error'); 
      System.debug(ltcr.error); 
  }else{ 
      System.debug('Success '+ltcr.data.size()); 
 		for(cadmus_una.MSGraphClient.ChannelData cd: ltcr.data) { 
      	System.debug('name: '+cd.name); 
      	System.debug('description: '+cd.description); 
      	System.debug('teamId: '+cd.teamId); 
      	System.debug('channelId: '+cd.channelId); 
      	System.debug('membershipType: '+cd.membershipType); 
      } 
  } 
  msGraphClient.commitRefreshToken();

listTeamMembers(userId, teamId)

List all members for a team
Signature
global ListMembersResponse listTeamMembers(String userId,String teamId)
Parameters
userId
Type: String
teamId
Returns
ListMembersResponse
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 cadmus_una.MSGraphClient.ListMembersResponse lmtr=msGraphClient.listTeamMembers(UserInfo.getUserId(),'60ae6356-a5fe-477f-b88c-4b2dd6a37b86'); 
 if(lmtr.isError()){ 
     System.debug('This is an error'); 
     System.debug(lmtr.error.message); 
 }else{ 
     System.debug('Success '+lmtr.data.size()); 
     for(cadmus_una.MSGraphClient.Member member : lmtr.data) { 
         System.debug('member id: '+member.membershipId); 
         System.debug('member email: '+member.email); 
         System.debug('member role: '+member.role); 
         System.debug('member userId: '+member.userId); 
         System.debug('member displayName: '+member.displayName); 
     } 
 } 
 msGraphClient.commitRefreshToken();

prepareRefreshToken(userId)

Call this method before calling multiple methods on the SharePoint API, just to make sure the credentials are up to date and this action has to happens once for all API calls.
Signature
global void prepareRefreshToken(String userId)
Parameters
userId
Type: String
User to call the SharePoint API with.
Example
 cadmus_una.MSGraphClient msGraphClient=new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId());

refreshTokenWithQueue(userId, queueables)

Signature
global String refreshTokenWithQueue(String userId,List<Queueable> queueables)

removeMemberFromTeam(userId, teamId, membershipId)

Removes a member of a team
Signature
global RemoveMemberResponse removeMemberFromTeam(String userId,String teamId,String membershipId)
Parameters
userId
Type: String
teamId
membershipId
Returns
RemoveMemberResponse
Example
 cadmus_una.MSGraphClient msGraphClient =new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
  cadmus_una.MSGraphClient.ListMembersResponse tdr=msGraphClient.listTeamMembers(UserInfo.getUserId(),'60ae6356-a5fe-477f-b88c-4b2dd6a37b86'); 
  if(tdr.isError()){ 
      System.debug('This is an error'); 
      System.debug(tdr.error.message); 
  }else{ 
      cadmus_una.MSGraphClient.Member memberToRemove=null; 
      for(cadmus_una.MSGraphClient.Member m:tdr.data){ 
          System.debug(m.toJson()); 
          System.debug(m.membershipId); 
          if(m.email=='igor.stuyver@pdfbutler.com'){ 
              memberToRemove=m; 
          } 
      } 
      cadmus_una.MSGraphClient.RemoveMemberResponse rmtr=msGraphClient.removeMemberFromTeam(UserInfo.getUserId(),'60ae6356-a5fe-477f-b88c-4b2dd6a37b86',memberToRemove.membershipId); 
      if(rmtr.isError()){ 
          System.debug('This is an error'); 
          System.debug(tdr.error.message); 
      }else{ 
          System.debug('Success '); 
      } 
  } 
  msGraphClient.commitRefreshToken();

removeMemberFromTeamChannel(userId, teamId, channelId, membershipId)

Remove a member from a Channel
Signature
global RemoveMemberResponse removeMemberFromTeamChannel(String userId,String teamId,String channelId,String membershipId)
Parameters
userId
Type: String
teamId
channelId
membershipId
Returns
RemoveMemberResponse
Example
 cadmus_una.MSGraphClient msGraphClient =new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
  cadmus_una.MSGraphClient.ListMembersResponse lm=msGraphClient.listTeamChannelMembers(UserInfo.getUserId(), 
 														'60ae6356-a5fe-477f-b88c-4b2dd6a37b86', 
 														'19:faea131b8dbd4565bc4a12051c7b9e26@thread.tacv2'); 
  if(lm.isError()){ 
      System.debug('This is an error'); 
      System.debug(lm.error); 
  }else{ 
      cadmus_una.MSGraphClient.Member memberToRemove=null; 
      for(cadmus_una.MSGraphClient.Member m:lm.data){ 
          System.debug(m.toJson()); 
          System.debug(m.membershipId); 
          if(m.email=='igor.stuyver@pdfbutler.com'){ 
              memberToRemove=m; 
          } 
      } 
      cadmus_una.MSGraphClient.RemoveMemberResponse rmtr=msGraphClient.removeMemberFromTeamChannel(UserInfo.getUserId(), 
 															'60ae6356-a5fe-477f-b88c-4b2dd6a37b86', 
 															'19:faea131b8dbd4565bc4a12051c7b9e26@thread.tacv2', 
 															memberToRemove.membershipId); 
      if(rmtr.isError()){ 
          System.debug('This is an error'); 
          System.debug(rmtr.error); 
      }else{ 
          System.debug('Success '); 
      } 
  } 
  msGraphClient.commitRefreshToken();

renameFolder(userId, url, isLibrary, basePath, sourceName, targetName)

Change the name of folder in a SharePoint Library
Signature
global static CollabMSGraphClient.SaveFileResponse renameFolder(String userId,String url, Boolean isLibrary, String basePath, String sourceName,String targetName)
Parameters
userId
Type: String
User ID
url
URR
isLibrary
Type: Boolean
Is <var>url</var> pointing to a Library ?
basePath
Type: String
Path to folder containing the driveItem to rename
sourceName
Type: String
driveItem source name
targetName
driveItem desired name
Returns
changed driveItem, the id field contains the list item id
Example
 //The folder we want to change is: /CollabAppExchange/Acme - 200 Widgets/CustomerInput/Unchanged 
 cadmus_una.MSGraphClient.renameFolder(UserInfo.getUserId(), 
           'https://cloudcrossingautomation.sharepoint.com/sites/COLLABORATIONTEST/Shared Documents', //=> Site and Library URL 
			 true, //=> handle this as a library, not a drive 
			 '/CollabAppExchange/Acme - 200 Widgets/CustomerInput',  //=> basePath to folder to change 
			 'Unchanged', //=> name of the folder to change 
			 'Changed')); //=> name of the folder to change it into

sanitizeFileName(dirtyFilename)

General cleanup of characters SharePoint cannot deal with
Signature
global String sanitizeFileName(String dirtyFilename)
Parameters
dirtyFilename
Type: String
Filename without the path
Returns
clean URL
Example
 // Becomes 'dsc001[new]_.jpeg' 
 MSGraphClient.sanitizeFileName('dsc001[new]/.jpeg')

sanitizeFolderName(dirtyFolderName)

General cleanup of characters SharePoint cannot deal with
Signature
global String sanitizeFolderName(String dirtyFolderName)
Parameters
dirtyFolderName
Type: String
Folder name not the entire path
Returns
clean URL

sanitizeFolderPath(dirtyFolderPath)

General cleanup of characters SharePoint cannot deal with
Signature
global String sanitizeFolderPath(String dirtyFolderPath)
Parameters
dirtyFolderPath
Type: String
Url path of the folder without filename (use{@link CollabMSGraphClient.sanitizeFileName})
Returns
clean URL
Example
 // Becomes 'dsc001[new]_jpegs_' 
 MSGraphClient.sanitizeFolderName('dsc001[new].jpegs/');

saveFile(userId, url, isLibrary, path, fileContent)

Saves a file to the specified path in a drive or document library.
Signature
global CollabMSGraphClient.SaveFileResponse saveFile(String userId, String url, Boolean isLibrary, String path, Blob fileContent)
Parameters
userId
Type: String
The user ID for which the file should be saved.
url
Type: String
The URL of the SharePoint site or document library where the file should be saved.
isLibrary
Type: Boolean
A boolean indicating whether the destination is a document library (true) or a SharePoint site (false).
path
Type: String
The path to save the file, including the file name and extension.
fileContent
Type: Blob
The content of the file as a Blob.
Returns
A SaveFileResponse object containing either the saved file's metadata or an error object.
Example
 String userId = 'user123'; 
 String url = 'https://example.sharepoint.com/sites/MySite/Shared Documents'; 
 Boolean isLibrary = true; 
 String path = 'MyCoolFolder/MyFile.txt'; 
 Blob fileContent = Blob.valueOf('Hello, world!'); //this can be the VersionData of a ContentVersion 
 
 cadmus_una.CollabMSGraphClient.SaveFileResponse response = cadmus_una.CollabMSGraphClient.saveFile(userId, url, isLibrary, path, fileContent); 
 if (response.error != null) { 
     System.debug('Error code: ' + response.error.code); 
     System.debug('Error message: ' + response.error.message); 
 } else { 
     System.debug('File saved: ' + response.data.name); 
 }

saveFile(userId, driveUrl, path, fileContent)

Signature
global CollabMSGraphClient.SaveFileResponse saveFile(String userId, String driveUrl, String path, Blob fileContent)

saveFileById(userId, driveId, parentId, fileName, fileContent)

Save file in a site drive using IDs
Signature
global CollabMSGraphClient.SaveFileResponse saveFileById(String userId, String driveId, String parentId, String fileName, Blob fileContent)
Parameters
userId
Type: String
user ID
driveId
Type: String
drive ID
parentId
Type: String
parent ID
fileName
Type: String
file name
fileContent
Type: Blob
file content
Returns
saved file

sendDraftEmail(userId, draftId)

Signature
global CollabMSGraphClient.SendEmailResponse sendDraftEmail(String userId,String draftId)

sendEmail(userId, emailMessage)

Send an email.
Signature
global CollabMSGraphClient.SendEmailResponse sendEmail(String userId,Messaging.SingleEmailMessage emailMessage)
Parameters
userId
Type: String
User Id to authenticate with
emailMessage
Email message to be saved in drafts
Returns
Draft Id.

updateContentType(userId, driveId, itemId, contentTypeId)

Update ContentType for file in a site drive using IDs. Warning: the files has to be part of a LIST.
Signature
global CollabMSGraphClient.SaveFileResponse updateContentType(String userId,String driveId, String itemId,String contentTypeId)
Parameters
userId
Type: String
user ID
driveId
drive ID
itemId
Type: String
parent ID
contentTypeId
custom ContentType for file
Returns
saved file, the id field contains the list item id

updateEntryInList(userId, siteId, listId, itemId, fields)

Updates a specific item in a specified list on a specific site.
Signature
global UpdateEntryToListResponse updateEntryInList(String userId,String siteId,String listId,String itemId,Map<String,Object> fields)
Parameters
userId
Type: String
The identifier of the user. This is used for authentication purposes and must be valid.
siteId
The identifier of the site where the list is located. The site must exist and the user must have appropriate permissions.
listId
The identifier of the list where the item will be updated. The list must exist within the specified site.
itemId
The identifier of the item to be updated in the list.
fields
A Map of fields for the list item to be updated. Each entry in the map represents a field, where the key is the field name and the value is the new field value.
Returns
UpdateEntryToListResponse An instance of the UpdateEntryToListResponse class. If the operation is successful, the 'error' field of the response will be null. If there was an error during the update operation (such as an invalid list Item Id, insufficient permissions, etc.), the 'error' field will contain details of the error.
Example
 cadmus_una.MSGraphClient msGraphClient = new cadmus_una.MSGraphClient(); 
 msGraphClient.prepareRefreshToken(UserInfo.getUserId()); 
 Map<String,Object> fields = new Map<String,Object>{'FieldName' => 'New Value'}; // Replace 'FieldName' and 'New Value' with the real field name and value. 
 cadmus_una.MSGraphClient.UpdateEntryToListResponse updateResponse = msGraphClient.updateEntryInList(UserInfo.getUserId(), 'YourSiteId', 'YourListId', 'YourItemId', fields); 
 System.debug('Update Response: ' + updateResponse.error); 
 msGraphClient.commitRefreshToken();

updateMetadataColumns(userId, driveId, itemId, fields)

Signature
global CollabMSGraphClient.SaveFileResponse updateMetadataColumns(String userId,String driveId,String itemId,Map<String,Object> fields)

urlEncodeFilePath(url)

Signature
global String urlEncodeFilePath(String url)

MSGraphClient.DriveItemPermission

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class DriveItemPermission

MSGraphClient.DriveItemPermission Properties

Name Signature
expirationDateTime
global String expirationDateTime
grantedToIdentitiesV2
global List<GrantedToIdentitiesV2> grantedToIdentitiesV2
hasPassword
global String hasPassword
id
global String id
isInherited
global Boolean isInherited
link
global SharingLink link
roles
global List<String> roles
shareId
global String shareId

MSGraphClient.DriveItemPermission Constructors

DriveItemPermission(parser)

Signature
global DriveItemPermission(JSONParser parser)

DriveItemPermission()

Signature
return new DriveItemPermission(parser)

MSGraphClient.DriveItemPermission Methods

parse(jsonString)

Signature
global DriveItemPermission parse(String jsonString)

MSGraphClient.DriveItemPermissions

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class DriveItemPermissions

MSGraphClient.DriveItemPermissions Properties

Name Signature
permissions
global List<DriveItemPermission> permissions

MSGraphClient.EmailAddress

Signature
global class EmailAddress

MSGraphClient.EmailAddress Properties

Name Signature
address
global String address
name
global String name

MSGraphClient.EmailAddress Constructors

EmailAddress(parser)

Signature
global EmailAddress(JSONParser parser)

MSGraphClient.GetDriveItemPermissionsData

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class GetDriveItemPermissionsData

MSGraphClient.GetDriveItemPermissionsData Properties

Name Signature
value
global List<DriveItemPermission> value

MSGraphClient.GetDriveItemPermissionsData Constructors

GetDriveItemPermissionsData(parser)

Signature
global GetDriveItemPermissionsData(JSONParser parser)

MSGraphClient.GetEntryFromListResponse

Signature
global class GetEntryFromListResponse

MSGraphClient.GetEntryFromListResponse Properties

Name Signature
data
global ListItemData data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.GetEntryFromListResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.GetListsFromSiteResponse

Signature
global class GetListsFromSiteResponse

MSGraphClient.GetListsFromSiteResponse Properties

Name Signature
data
global List<SharePointList> data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.GetListsFromSiteResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.GetSharingPermissionResponse

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class GetSharingPermissionResponse

MSGraphClient.GetSharingPermissionResponse Properties

Name Signature
data
global DriveItemPermission data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.GetSharingPermissionResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.GetSharingPermissionsResponse

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class GetSharingPermissionsResponse

MSGraphClient.GetSharingPermissionsResponse Properties

Name Signature
data
global GetDriveItemPermissionsData data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.GetSharingPermissionsResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.GetSiteResponse

Signature
global class GetSiteResponse

MSGraphClient.GetSiteResponse Properties

Name Signature
data
global SiteData data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.GetSiteResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.GrantedToIdentitiesV2

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class GrantedToIdentitiesV2

MSGraphClient.GrantedToIdentitiesV2 Properties

Name Signature
user
global User user

MSGraphClient.GrantedToIdentitiesV2 Constructors

GrantedToIdentitiesV2(parser)

Signature
global GrantedToIdentitiesV2(JSONParser parser)

MSGraphClient.InvitedUser

Signature
global class InvitedUser

MSGraphClient.InvitedUser Properties

Name Signature
id
global String id

MSGraphClient.InvitedUser Constructors

InvitedUser(parser)

Signature
global InvitedUser(JSONParser parser)

MSGraphClient.InvitedUserGraphResponse

Signature
global class InvitedUserGraphResponse

MSGraphClient.InvitedUserGraphResponse Properties

Name Signature
id
global String id
invitedUser
global InvitedUser invitedUser
invitedUserDisplayName
global String invitedUserDisplayName
invitedUserEmailAddress
global String invitedUserEmailAddress
invitedUserMessageInfo
global InvitedUserMessageInfo invitedUserMessageInfo
inviteRedeemUrl
global String inviteRedeemUrl
inviteRedirectUrl
global String inviteRedirectUrl
odata_context
global String odata_context
resetRedemption
global Boolean resetRedemption
sendInvitationMessage
global Boolean sendInvitationMessage
status
global String status

MSGraphClient.InvitedUserGraphResponse Constructors

InvitedUserGraphResponse(parser)

Signature
global InvitedUserGraphResponse(JSONParser parser)

MSGraphClient.InvitedUserMessageInfo

Signature
global class InvitedUserMessageInfo

MSGraphClient.InvitedUserMessageInfo Properties

Name Signature
ccRecipients
global List<CcRecipients> ccRecipients
customizedMessageBody
global String customizedMessageBody
messageLanguage
global String messageLanguage

MSGraphClient.InvitedUserMessageInfo Constructors

InvitedUserMessageInfo(parser)

Signature
global InvitedUserMessageInfo(JSONParser parser)

MSGraphClient.InviteGuestResponse

Signature
global class InviteGuestResponse

MSGraphClient.InviteGuestResponse Properties

Name Signature
data
global Member data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.InviteGuestResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.ListItemData

Signature
global class ListItemData

MSGraphClient.ListItemData Properties

Name Signature
fields
global Map<String,Object> fields
id
global String id

MSGraphClient.ListItemData Constructors

ListItemData(parser)

Signature
global ListItemData(JSONParser parser)

MSGraphClient.ListMembersResponse

Signature
global class ListMembersResponse

MSGraphClient.ListMembersResponse Properties

Name Signature
data
global List<Member> data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.ListMembersResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.ListTeamChannelsResponse

Signature
global class ListTeamChannelsResponse

MSGraphClient.ListTeamChannelsResponse Properties

Name Signature
data
global List<ChannelData> data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.ListTeamChannelsResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.Member

Signature
global class Member

MSGraphClient.Member Properties

Name Signature
displayName
global String displayName
email
global String email
membershipId
global String membershipId
role
global MemberRole role
userId
global String userId

MSGraphClient.Member Constructors

Member()

Signature
global Member()

Member(parser)

Signature
global Member(JSONParser parser)

MSGraphClient.Member Methods

toJson()

Signature
global String toJson()

MSGraphClient.MSGraphClientStub

Default mock returning only succesful responses. The below will show how the Stub behaves and which values are returned so they can be used in testing and asserting.
Signature
global virtual class MSGraphClientStub implements StubProvider
Example
 getSiteDrive -> GetDriveResponseData('42'); 
 getDriveItemByPath -> GetDriveResponseData('42'); 
 saveFileById -> SaveFileResponse('4242','test',4269,'https://example.com'); 
 createFolder -> SaveFileResponse('4242','test',4269,'https://example.com'); 
 renameFolder -> SaveFileResponse('4242','test',4269,'https://example.com');

MSGraphClient.RemoveMemberResponse

Signature
global class RemoveMemberResponse

MSGraphClient.RemoveMemberResponse Properties

Name Signature
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.RemoveMemberResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.ResponseOrError

Signature
global class ResponseOrError

MSGraphClient.ResponseOrError Properties

Name Signature
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.SharePointList

Signature
global class SharePointList

MSGraphClient.SharePointList Properties

Name Signature
createdDateTime
global Datetime createdDateTime
id
global String id
lastModifiedDateTime
global Datetime lastModifiedDateTime
name
global String name
properties
global SharepointListProperties properties

MSGraphClient.SharePointList Constructors

SharePointList(parser)

Signature
public SharePointList(JSONParser parser)
Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class SharingLink

MSGraphClient.SharingLink Constructors

Signature
global SharingLink(JSONParser parser)
Signature
return new SharingLink(parser)

MSGraphClient.SharingLink Methods

consumeObject(parser)

Signature
global void consumeObject(System.JSONParser parser)

parse(jsonString)

Signature
global SharingLink parse(String jsonString)

MSGraphClient.SiteData

Signature
global class SiteData

MSGraphClient.SiteData Properties

Name Signature
createdDateTime
global Datetime createdDateTime
displayName
global String displayName
id
global String id
lastModifiedDateTime
global Datetime lastModifiedDateTime
name
global String name
webUrl
global String webUrl

MSGraphClient.SiteData Constructors

SiteData(parser)

Signature
public SiteData(JSONParser parser)

MSGraphClient.TeamData

Signature
global class TeamData

MSGraphClient.TeamData Properties

Name Signature
description
global String description
name
global String name
teamId
global String teamId

MSGraphClient.TeamData Methods

toJson()

Signature
global String toJson()

MSGraphClient.TeamDataResponse

Signature
global class TeamDataResponse

MSGraphClient.TeamDataResponse Properties

Name Signature
data
global TeamData data
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.TeamDataResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.UpdateEntryToListResponse

Signature
global class UpdateEntryToListResponse

MSGraphClient.UpdateEntryToListResponse Properties

Name Signature
error
global CollabMSGraphClient.GraphErrorResponse error

MSGraphClient.UpdateEntryToListResponse Methods

isError()

Signature
global Boolean isError()

isError(errorCode)

checks if there is an error with a certain error-code present
Signature
global Boolean isError(String errorCode)

MSGraphClient.UploadSession

Signature
@JsonAccess(Serializable='always' Deserializable='always')
global class UploadSession

MSGraphClient.UploadSession Properties

Name Signature
expirationDateTime
global String expirationDateTime
uploadUrl
global String uploadUrl

MSGraphClient.UploadSession Constructors

UploadSession(parser)

Signature
UploadSession(JSONParser parser)

MSGraphClient.User

Signature
global class User

MSGraphClient.User Properties

Name Signature
displayName
global String displayName
email
global String email
id
global String id

MSGraphClient.User Constructors

User(parser)

Signature
global User(JSONParser parser)