OfficeDev / Office-365-SDK-for-Android

Microsoft Services SDKs for Android produced by MS Open Tech.
https://dev.office.com/android
Other
224 stars 74 forks source link

Cannot attach Contact as ItemAttachment to an email #75

Open JohnMAustin78 opened 9 years ago

JohnMAustin78 commented 9 years ago

Folks, The following code raises an internal server exception. The item object in the 2nd argument of my method actually cast from a valid Contact object. The client is verified to be valid, the mail Id came from a new message I created and did not send yet. The message sits in the user's draft mail message folder.

I get the following internal server (501) error:

"Object reference not set to an instance of an object”

/**
 * Gets a message out of the user's draft folder by id and adds a text file attachment
 *
 * @param mailId  The id of the draft email that will get the attachment
 * @param itemToAttach The mail message to attach
 * @return Boolean. The result of the operation. True if success
 * @version 1.0
 */
public Boolean addItemAttachment(
        String mailId
        , Item itemToAttach) throws ExecutionException, InterruptedException {
    ItemAttachment itemAttachment = new ItemAttachment();
    itemAttachment.setName(itemToAttach.getClass().getName());
    itemAttachment.setItem(itemToAttach);
    itemAttachment.setContentType(itemToAttach.getClass().getName());
    itemAttachment.setIsInline(false);
    itemAttachment.setId(itemToAttach.getId());
    mMailClient
            .getMe()
            .getMessages()
            .getById(mailId)
            .getAttachments()
            .add(itemAttachment)
            .get();
    return true;
}
marcote commented 9 years ago

Hi John. If you try to do the same thing using a REST client like Fiddler, can you reproduce the behavior?

JohnMAustin78 commented 9 years ago

Good question. I will give that a try. From: Marcos Torres notifications@github.com<mailto:notifications@github.com> Reply-To: OfficeDev/Office-365-SDK-for-Android reply@reply.github.com<mailto:reply@reply.github.com> Date: Monday, April 20, 2015 at 9:46 AM To: OfficeDev/Office-365-SDK-for-Android Office-365-SDK-for-Android@noreply.github.com<mailto:Office-365-SDK-for-Android@noreply.github.com> Cc: John Austin johnau@microsoft.com<mailto:johnau@microsoft.com> Subject: Re: [Office-365-SDK-for-Android] Cannot attach Contact as ItemAttachment to an email (#75)

Hi John. If you try to do the same thing using a REST client like Fiddler, can you reproduce the behavior?

Reply to this email directly or view it on GitHubhttps://github.com/OfficeDev/Office-365-SDK-for-Android/issues/75#issuecomment-94505256.

JohnMAustin78 commented 9 years ago

Hi Marcos,

I've tried the request using the Charles Proxy tool. I get the same error that I got in the response to the call using the client library.

Request The following is the request JSON payload when a contact is attached:

{ "Item": { "BusinessAddress": { "@odata.type": "#Microsoft.OutlookServices.PhysicalAddress" }, "BusinessPhones": [null, null], "DisplayName": "New Contact created on 2015-23-03 at 11:46", "EmailAddresses": [{ "Address": "AlexD@patsoldemo4.onmicrosoft.com", "Name": "Alex Darrow", "@odata.type": "#Microsoft.OutlookServices.EmailAddress" }, null, null], "FileAs": "", "GivenName": "New Contact", "HomeAddress": { "@odata.type": "#Microsoft.OutlookServices.PhysicalAddress" }, "HomePhones": [null, null], "ImAddresses": [null, null, null], "MobilePhone1": "5554251212", "OtherAddress": { "@odata.type": "#Microsoft.OutlookServices.PhysicalAddress" }, "ParentFolderId": "AAMkADE5NTIzMjhjLWFkYjEtNDdjYS04NDBmLWMzYjNkZDM2ZDAzMAAuAAAAAACYmH-NJgoiR5Hddx6ToBrSAQA7Z34e4-q-Ta7-0CC9gFcSAAAAAAEOAAA=", "Surname": " created on 2015-23-03 at 11:46", "Categories": [], "ChangeKey": "EQAAABYAAAA7Z34e4/q/Ta7/0CC9gFcSAAAKOuzn", "DateTimeCreated": "2015-03-23T18:45:03.0000000Z", "DateTimeLastModified": "2015-03-25T21:48:59.0000000Z", "Id": "AAMkADE5NTIzMjhjLWFkYjEtNDdjYS04NDBmLWMzYjNkZDM2ZDAzMABGAAAAAACYmH-NJgoiR5Hddx6ToBrSBwA7Z34e4-q-Ta7-0CC9gFcSAAAAAAEOAAA7Z34e4-q-Ta7-0CC9gFcSAAAH3Go5AAA=", "@odata.type": "#Microsoft.OutlookServices.Contact" }, "ContentType": "com.microsoft.outlookservices.Contact", "IsInline": false, "Name": "com.microsoft.outlookservices.Contact", "Id": "AAMkADE5NTIzMjhjLWFkYjEtNDdjYS04NDBmLWMzYjNkZDM2ZDAzMABGAAAAAACYmH-NJgoiR5Hddx6ToBrSBwA7Z34e4-q-Ta7-0CC9gFcSAAAAAAEOAAA7Z34e4-q-Ta7-0CC9gFcSAAAH3Go5AAA=", "@odata.type": "#Microsoft.OutlookServices.ItemAttachment" }

Response { "error": { "code": "ErrorInternalServerError", "message": "Object reference not set to an instance of an object." } }

From: Marcos Torres notifications@github.com<mailto:notifications@github.com> Reply-To: OfficeDev/Office-365-SDK-for-Android reply@reply.github.com<mailto:reply@reply.github.com> Date: Monday, April 20, 2015 at 9:46 AM To: OfficeDev/Office-365-SDK-for-Android Office-365-SDK-for-Android@noreply.github.com<mailto:Office-365-SDK-for-Android@noreply.github.com> Cc: John Austin johnau@microsoft.com<mailto:johnau@microsoft.com> Subject: Re: [Office-365-SDK-for-Android] Cannot attach Contact as ItemAttachment to an email (#75)

Hi John. If you try to do the same thing using a REST client like Fiddler, can you reproduce the behavior?

Reply to this email directly or view it on GitHubhttps://github.com/OfficeDev/Office-365-SDK-for-Android/issues/75#issuecomment-94505256.

meneja01 commented 9 years ago

I am having an issue with null references for attachments as well. Whenever I try to do a .getAttachments() on a Message object, I get null returned, despite the .getHasAttachments() flag being set to true.

marcote commented 9 years ago

Let me review this please. Thanks.