msgraph-sdk-javascript icon indicating copy to clipboard operation
msgraph-sdk-javascript copied to clipboard

cannot get attachments for messages

Open arceus-jia opened this issue 7 years ago • 6 comments

Bug Report

Prerequisites

  • [ ] Can you reproduce the problem?
  • [ ] Are you running the latest version?
  • [ ] Are you reporting to the correct repository?
  • [ ] Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

I'm trying to use graph api to get attachments for a message , but it seems not work. If I use graph function, it returns nothing.

		let accessToken = await getAccessToken(emailConnect.refresh_token);
		const client = graph.Client.init({
			authProvider: done => {
				done(null, accessToken);
			}
		});
		url = `/me/messages/${messageId}/attachments`;
		result = await client.api(url).get();
		console.log('result1..',result);

But if I just simulate a http request, or test it in graph explorer, it will return the correct data.

		url = `https://graph.microsoft.com/v1.0/${url}`
		result = await axios.get(url,{
			headers:{
				'Authorization': `Bearer ${accessToken}`
			}
		});
		console.log('result2..',result.data);

I've tested in node 11.12.0 and node 10.4.1. Thanks very much.

Console Errors: [Is there any console error]

Screenshots: [If applicable, add screenshots to help explain your problem]

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on...]

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Additional context

Add any other context about the problem here..

arceus-jia avatar Jul 19 '19 11:07 arceus-jia

Hi @arceus-jia Can you wrap the above piece of code in a try catch and post me back the error you are getting for that request?

muthurathinam avatar Jul 23 '19 04:07 muthurathinam

Hi @muthurathinam Thank you for answering my question. it was super strange, I've wrapped code, but it showed nothing. here is my code:

async function getAttachment() {
	try {
		let accessToken = await getAccessToken(emailConnect.refresh_token);
		const client = graph.Client.init({
			authProvider: done => {
				done(null, accessToken);
			}
		});
		let url, result;
		let messageId =
			'AQMkADAwATMwMAItMWRiYS05ZjVkLTAwAi0wMAoARgAAA9KACsmQfQlEmuXIJaE5UXUHAHdiil39hRJChJQVDhBqW4gAAAIBDAAAAHdiil39hRJChJQVDhBqW4gAAAA3TRC5AAAA';

		url = `/me/messages/${messageId}/attachments`;
		result = await client.api(url).get();
		console.log('result1..', result);

		url = `https://graph.microsoft.com/v1.0/${url}`;
		result = await axios.get(url, {
			headers: {
				Authorization: `Bearer ${accessToken}`
			}
		});
		console.log('result2..', result.data);

	} catch (err) {
		console.log('err..', err);
	}
}

If I keep this line of code "result = await client.api(url).get();", the program will neither print result1 nor print err. Not even running the next code, it just exit. but if I don't call this, just use axios to send a http request, it will print the right answer.

arceus-jia avatar Jul 26 '19 10:07 arceus-jia

Getting this issue as well, request works when I run it in postman.

Experiencing something similar when I run this in my IDE (surrounded by try/catch). Code just stops when I step over the line, no error or anything.

changus avatar Aug 08 '19 01:08 changus

@arceus-jia @changus I believe you are using the 1.7.0 version of the SDK. can you try the same code with out preview version 2.0.0-Preview.4 ?

muthurathinam avatar Aug 08 '19 05:08 muthurathinam

@muthurathinam after i upgraded to 2.0.0-Preview.4, it started working! I do want to point out that I also needed to include the isomorphic-fetch package that I didn't need to include before.

Thank you!

changus avatar Aug 08 '19 17:08 changus

@muthurathinam Yes, I've changed to 2.0.0-Preview.4, it works! Thank you!

arceus-jia avatar Aug 09 '19 06:08 arceus-jia