locked
HttpRequest failed with sendInvitation RRS feed

  • Question

  • Hello everyone, i got  an HttpRequest failed error while trying to send invitation to the contacts

    i am not sure what could have caused that error, could anyone provide some information about this ? thank you

                for (var i = 0; i < contactCollection.get_length(); i++) {
                        var contact_item = contactCollection.get_item(i);
                        var test_email = contact_item.get_emails();
                      contact_item.sendInvitation(main_email, subject, body_text, function(sentEmailsEvt){
                            Sys.Debug.trace("inviteSomeone " + sentEmailsEvt.get_resultCode() + ':' +sentEmailsEvt.get_error().message);
                       
                        });
                    }

    Thursday, October 21, 2010 8:28 AM

All replies

  • I had the same problem.  Use the IE Developer Tool to debug the script.  Set a breakpoint on the callback function and examine the EXData structure.  There is a more detail error message that actually describes the problem unlike the exposed get_error(method) which tells you nothing of value.

    Typical problems are:

    -invalid CID (they must be converted to hex, try determining that in the doc)

    -invalid FROM address (can't use the sender's email address, not quite sure what is required, don't look to the doc for answers)

    -invalid TO address (cannot include senders CID, only include CID of friends in the TO address)

    If you get the email to send successfully, post the detail here because despite getting this call to work I still do not actually receive any emails to the recipients.  And so far I have been unable to get any useful answers on this forum or otherwise.

    Good luck.

    Friday, November 5, 2010 11:28 AM
  • Finally I succeeded in sending an email.

    I used the IE developer tools for script debugging. The debugger told me to update channel.htm. So I did (http://go.microsoft.com/fwlink/?LinkId=195245).

    First, my app sign in the user and retrieves all contacts. Then I use the following code to send emails:

    Microsoft.Live.Core.Namespace.using("wl:Microsoft.Live");<br/>
    <br/>
    function sendMailToContacts(contacts) <br/>
    {<br/>
    	var from = "mynamehere";<br/>
    	var subject = "test email " + new Date();<br/>
    	var body = "test body";<br/>
    	var invitations = [];<br/>
    	for (var i=0;i<contacts.length;i++) <br/>
    	{<br/>
    		var contact = contacts[i];<br/>
    		if (contact.get_cid())<br/>
    		{<br/>
    			var recipientCIDs = [contact.get_cid().toString(16)];<br/>
    			var subject = "test email to " +getContactName(contact)+", "+ new Date();<br/>
    			var invitation = wl.$create_EmailInvitation(from, subject, body, recipientCIDs);<br/>
    			invitations.push(invitation);<br/>
    			log("sendMailToContacts, sending to: "+getContactName(contact), contact.get_cid(), contact.get_isFriend());<br/>
    		}<br/>
    		else<br/>
    		{<br/>
    			log("sendMailToContacts, no cid or no friend: "+getContactName(contact));<br/>
    		}<br/>
    	}<br/>
    	//<br/>
    	dataContext.sendInvitations(invitations, function (e) {<br/>
    			var failed = String(e.get_failed());//nr of failed messages<br/>
    			var error = e.get_error();<br/>
    			log("sendMailToContacts callback: "+name);<br/>
    			log("Success: "+(e.get_resultCode() === wl.AsyncResultCode.success));<br/>
    			logEvent(e);<br/>
    	});<br/>
    }<br/>
    <br/>
    function getContactName(contact)<br/>
    {<br/>
    	var name = contact.get_formattedName();<br/>
    	if (name==undefined || name=="") name = contact.get_title();<br/>
    	return name;<br/>
    }<br/>
    
    

    (The log function displays text in the browser and is not included in the script above! Replace by alert if you like.)

    Still, the event arg in the callback shows an error (HTTPRequest Error), but the call succeeds (e.get_resultCode() === wl.AsyncResultCode.success), with the following conditions:

    • the contact has a CID (not all do!) (Contact.get_cid())
    • the cid has to be converted to hex (using .toString(16)) (Thanks Bill Murray'!)
    • the contact is a friend (Contact.get_isFriend())
    • you cannot send more than 1 email to the same contact in the same call

    If only 1 contact does not fulfil these conditions, then all emails fail... So make sure you test all conditions before sending.

    I did not get Contact.sendInvitation to work, only IDataContext.sendInvitations.

    Wednesday, November 24, 2010 10:44 AM