-
Notifications
You must be signed in to change notification settings - Fork 10
Sample Operations List
This wiki page lists all snippet operations used in this sample. Although these calls against the Microsoft Graph service are covered in the project, you can use it as a quick and copy/paste-able reference for tasks in your own sample.
Some of these operations do require parameter input that will be called out as needed. For implementation specifics, please see the Snippets.m file in the project. There are a number of helper methods there to create different sample objects (events, mail messages, and groups) to pass into these functions. For authentication specifics including creating and initializing the MSGraphClient used in these calls please see the sample.
For each snippet you'll get a description, required parameters, and required user account permissions to run this operation.
Get Me
// Returns select information about the signed-in user from Azure Active Directory. Applies to personal or work accounts.
// Params: none
[[[self.graphClient me] request] getWithCompletion:^(MSGraphUser *response, NSError *error) {
}];
Get Users
// Returns all of the users in your tenant's directory. Applies to personal or work accounts.
// Params: none
[[[self.graphClient users] request] getWithCompletion:^(MSCollection *response, MSGraphUsersCollectionRequest *nextRequest, NSError *error) {
}];
Get Drive
// Gets the signed-in user's drive from OneDrive. Applies to personal or work accounts
// Params: none
[[[[self.graphClient me] drive] request] getWithCompletion:^(MSGraphDrive *drive, NSError *error){
}];
Get Events
// Gets the signed-in user's events. Applies to personal or work accounts.
// Params: none
[[[[self.graphClient me] events] request] getWithCompletion:^(MSCollection *response, MSGraphUserEventsCollectionRequest *nextRequest, NSError *error) {
}];
Create Event
// Create an event in the signed in user's calendar. Applies to personal or work accounts.
// Params: addEvent - MSGraphEvent
[[[[self.graphClient me] events] request] addEvent:event withCompletion:^(MSGraphEvent *response, NSError *error) {
}];
Update Event
// Updates an event in the signed in user's calendar. Applies to personal or work accounts.
// Params: events - MSGraphEvent Id
[[[[self.graphClient me] events:event.entityId] request] update:event withCompletion:^(MSGraphEvent *response, NSError *error) {
}];
Delete Event
// Deletes an event in the signed in user's calendar. Applies to personal or work accounts.
// Params: events - MSGraphEvent Id
[[[[self.graphClient me] events:event.entityId] request] deleteWithCompletion:^(NSError *error) {
}];
Get Messages
// Gets the signed-in user's messages. Applies to personal or work accounts.
// Params: none
[[[[self.graphClient me] messages] request] getWithCompletion:^(MSCollection *response, MSGraphUserMessagesCollectionRequest *nextRequest, NSError *error) {
}];
Send Message
// Create and send a message as the signed-in user. Applies to personal or work accounts.
// Params: sendMailWithMessage - MSGraphMessage
MSGraphUserSendMailRequestBuilder *requestBuilder = [[self.graphClient me]sendMailWithMessage:message saveToSentItems:true];
MSGraphUserSendMailRequest *mailRequest = [requestBuilder request];
[mailRequest executeWithCompletion:^(NSDictionary *response, NSError *error) {
}];
Get User Files
// Returns all of the user's files. Applies to personal or work accounts.
// Params: none
[[[[[[self.graphClient me]drive]root]children]request]getWithCompletion:^(MSCollection *response, MSGraphDriveItemChildrenCollectionRequest *nextRequest, NSError *error) {
}];
Create Text File
// Create a text file in the signed in user's OneDrive account- If a file already exists it will be overwritten. Applies to personal or work accounts
// Params: itemByPath -file location, and uploadFromData - NSData
[[[[[[self.graphClient me] drive] root] itemByPath:@""] contentRequest] uploadFromData:uploadData completion:^(MSGraphDriveItem *response, NSError *error) {
}];
Create Folder
// Creates a new folder in the signed in user's OneDrive account. Applies to personal or work accounts
MSGraphDriveItem *driveItem = [[MSGraphDriveItem alloc] initWithDictionary:@{[MSNameConflict rename].key : [MSNameConflict rename].value}];
driveItem.name = @"TestFolder";
driveItem.folder = [[MSGraphFolder alloc] init];
// Use itemByPath as below to create a subfolder under an existing folder
[[[[[self.graphClient me]drive] root] request] getWithCompletion:^(MSGraphDriveItem *response, NSError *error) {
}];
Download File
// Downloads a file into the signed in user's OneDrive account. Applies to personal or work accounts.
// Params: items - MSGraphDriveItem Id
[[[[[self.graphClient me] drive] items:driveItem.entityId] contentRequest] downloadWithCompletion:^(NSURL *location, NSURLResponse *response, NSError *error) {
}];
Update File
// Uploads a file in the signed in user's OneDrive account. Applies to personal or work accounts.
// Params: items - MSGraphDriveItem Id, and uploadFromData - NSData
NSString *testText = @"NewTextValue";
NSData *uploadData = [testText dataUsingEncoding:NSUTF8StringEncoding];
[[[[[self.graphClient me] drive] items:driveItem.entityId] contentRequest] uploadFromData:uploadData completion:^(MSGraphDriveItem *response, NSError *error) {
}];
Rename File
// Renames a file in the signed in user's OneDrive account. Applies to personal or work accounts.
// Params: items - MSGraphDriveItem Id, and update - MSGraphDriveItem
[[[[[self.graphClient me] drive] items:driveItem.entityId] request] update:driveItem withCompletion:^(MSGraphDriveItem *response, NSError *error) {
}];
Delete File
// Deletes a file in the signed in user's OneDrive account. Applies to personal or work accounts.
// Params: items - MSGraphDriveItem Id
[[[[[self.graphClient me] drive] items:driveItem.entityId] request] deleteWithCompletion:^(NSError *error) {
}];
Get Manager
// Get user's manager if they have one. Applies to work accounts only. // Params: none
[[[[self.graphClient me] manager] request] getWithCompletion:^(MSGraphDirectoryObject *response, NSError *error) {
}];
Get Directs
// Get user's direct reports. Applies to work accounts only.
// Params: none
[[[[self.graphClient me] directReports] request] getWithCompletion:^(MSCollection *response, MSGraphUserDirectReportsCollectionWithReferencesRequest *nextRequest, NSError *error) {
}];
Get Photos
// Gets the signed-in user's photo data if they have a photo. This snippet will return metadata for the user photo. Applies to work accounts only.
// Params: none
[[[[self.graphClient me]photo]request]getWithCompletion:^(MSGraphProfilePhoto *response, NSError *error) {
}];
Create User
// Creates a new user in the tenant. Applicable to work accounts with admin rights.
// Params: addUser - MSGraphUser - see Snippets.m in the project for creating object
[[[self.graphClient users] request] addUser:newUser withCompletion:^(MSGraphUser *response, NSError *error) {
}];
Get User Groups
// Gets a collection of groups that the signed-in user is a member of. Applicable to work accounts with admin rights.
// Params: none
[[[[self.graphClient me] memberOf] request] getWithCompletion:^(MSCollection *response, MSGraphUserMemberOfCollectionWithReferencesRequest *nextRequest, NSError *error) {
}];
Get All Groups
// Returns all of the groups in your tenant's directory. Applicable to work accounts with admin rights.
// Params: none
[[[self.graphClient groups] request] getWithCompletion:^(MSCollection *response, MSGraphGroupsCollectionRequest *nextRequest, NSError *error) {
}];
Get Single Group
// Gets a specified group. Applicable to work accounts with admin rights.
// Params: MSGraphGroup Id
[[[[self.graphClient groups] group:group.entityId] request] getWithCompletion:^(MSGraphGroup *response, NSError *error) {
}];
Get Members
// Gets a specific group's members. Applicable to work accounts with admin rights.
// Params: // Params: MSGraphGroup Id
[[[[[self.graphClient groups] group:group.entityId] members] request] getWithCompletion:^(MSCollection *response, MSGraphGroupMembersCollectionWithReferencesRequest *nextRequest, NSError *error) {
}];
Get Owners
// Gets a specific group's owners. Applicable to work accounts with admin rights.
// Params: Params: MSGraphGroup Id
[[[[[self.graphClient groups] group:group.entityId] owners] request] getWithCompletion:^(MSCollection *response, MSGraphGroupOwnersCollectionWithReferencesRequest *nextRequest, NSError *error) {
}];
Create Group
// Creates a group in user's account. Applicable to work accounts with admin rights.
Params: MSGraphGroup
[[[self.graphClient groups] request] addGroup:group withCompletion:^(MSGraphGroup *response, NSError *error) {
}];
Update Group
// Updates a group in user's account. Applicable to work accounts with admin rights.
// Params: group - MSGraphGroup Id, and update - MSGraphGroup
[[[[self.graphClient groups] group:group.entityId] request] update:group
withCompletion:^(MSGraphGroup *response, NSError *error) {
}];
Delete Group
// Deletes a group in user's account. Applicable to work accounts with admin rights.
// Params: group - MSGraphGroup Id
[[[[self.graphClient groups] group:group.entityId] request] deleteWithCompletion:^(NSError *error) {
}];