Working with Invitations

Gg262070.note(en-us,MSDN.10).gifNote:
Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

Invitations provide a way for users to send email invitations to their Windows Live friends. For example, a user could invite friends to go see a movie or participate in an online gaming session.

A Windows Live friend is a contact that has a Windows Live ID user account and with whom another user has established a two-way relationship; that is, a Windows Live user who has been invited by another Windows Live user to be a friend, and who has accepted the invitation.

A user can send an invitation either to a specific contact or to a group of contacts. To provide the user with the ability to create and send an invitation to a specific contact, use the sendInvitation method. To create invitations for multiple recipients, call the createEmailInvitation method, and then call the sendInvitations method to send the invitations.

To send an invitation to an individual contact, call Contact.sendinvitation as shown in the following example.

function inviteSomeone(contact) {
    var from = "nunobento@hotmail.com";
    var subject = "Go to a show?";
    var body = "Hey, want to go check out some bands?" + new Date();
    var callback = "onSendInvitation";
    contact.sendInvitation(from, subject, body, callback);
}
function onSendInvitation(sentEmailsEvt) {
    Sys.Debug.trace("inviteSomeone " + (isSuccess(sentEmailsEvt) ? "Success" : "Failure") + " returned from sending email invitation to " + contact.get_formattedName())
} 

Note that the code for obtaining a recipient contact has been omitted for brevity.

To send an invitation to a group of recipients, first create an array of invitations. Next, iterate through a list of contacts, using Contact.createEmailInvitation to create an invitation for each contact and then adding that invitation to the array. Finally, call IDataContext.sendInvitations to send the invitations.

The following example shows how to send an invitation to a group. As with the previous example, the code for obtaining the list of contacts has been omitted for brevity.

function inviteGroup(contactList) {
    var invitations = new Array();
    for (var i = 0; i < contactList.get_length(); i++) {
        var contact = contactList.getItem(i);
        if (contact.get_isFriend()) {invitations.push(contact.createEmailInvitation("nunobento@hotmail.com", "Game Tonight?", "Hey " + contact.get_firstName() + ", care to join us for a bit of friendly competition?"));
        }
    }
    Microsoft.Live.App.get_dataContext().sendInvitations(invitations);
}


You can also send an invitation to recipients by calling a special static constructor to create the invitation, and by using a list of recipient CID values instead of instances of the Microsoft.Live.Services.Contact class. The following example demonstrates this approach.

var invite = Microsoft.Live.$create_EmailInvitation(from, subject, body, cids);
var invitations = [invite];
Microsoft.Live.App.get_dataContext().sendInvitations(invitations);

Show: