public async Task <BulkInviteResults> ProcessBulkInvitations(BulkInviteSubmission submission) { var res = new BulkInviteResults(submission.Id); try { var batch = new GraphBatch(); int counter = 0; var inviteEndPoint = string.Format("/{0}/invitations", Settings.GraphApiVersion); var headerColl = new Dictionary <string, string> { { "Content-Type", "application/json" } }; var items = await BulkInviteSubmission.GetGuestRequestsPending(submission.Id); foreach (var item in items) { counter++; // Setup invitation GraphInvitation invitation = new GraphInvitation() { InvitedUserDisplayName = item.EmailAddress, InvitedUserEmailAddress = item.EmailAddress, InviteRedirectUrl = _profileUrl, SendInvitationMessage = (!Settings.UseSMTP), InvitedUserType = submission.MemberType.ToString() }; if (submission.InvitationMessage.Length > 0) { invitation.InvitedUserMessageInfo = new InvitedUserMessageInfo { CustomizedMessageBody = submission.InvitationMessage }; } batch.Requests.Add(new BulkInviteRequest { Id = counter.ToString(), GuestRequestId = item.Id, Request = item, Method = "POST", Headers = headerColl, Url = inviteEndPoint, Body = invitation }); } /* NOTE: * This process is designed to leverage the Microsoft Graph batch processor: * https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching * However, the batch processor is currently (2018) in preview and limited to 20 submissions per request * For the time being, we'll loop the collection and make individual synchronous calls */ //res = SubmitToGraphBatch(batch, submission, userId); res = await SubmitLocally(batch, submission); return(res); } catch (Exception ex) { var msg = "Error processing bulk invitation"; res.ErrorMessage = Logging.WriteToAppLog(msg, System.Diagnostics.EventLogEntryType.Error, ex); await BulkInviteResults.AddItem(res); return(res); } }