Microsoft Graph API: Download OneDrive shared link - microsoft-graph-api

I sent an email with an OneDrive reference type attachment.
Now I want to download it by the Microsoft Graph API. Here I get an attachment object
https://graph.microsoft.com/beta/me/messages/xxx/attachments
with a SourceUrl:
https://1drv.ms/w/s!Apb0GUJt7b5wbaxZ8zBORpDY708
When I'm trying to download it from the OneDrive:
https://graph.microsoft.com/beta/shares/s!Apb0GUJt7b5wbaxZ8zBORpDY708
I get this error:
"The provided share id was malformed"
and when I base64 encode the entire SourceUrl:
https://graph.microsoft.com/beta/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3cvcyFBcGIwR1VKdDdiNXdiYXhaOHpCT1JwRFk3MDg
I get this error:
"The site in the encoded share URI is invalid"
The solution provided here doesn't work:
The site in the encoded share URI is invalid

Related

Video as attachment in email

I use graph api to send emails to users. Is it possible to add video as attachment to email ? I converted .mp4 to binary string, set contentType to video/mp4, id to new Guid.
I created a request to send email, got correct response, but I don't recieve email (emails without videos works fine).
Documentation is not really helpful.
If the file size is between 3MB and 150MB, create an upload session, and iteratively use PUT to upload ranges of bytes of the file until you have uploaded the entire file. A header in the final successful PUT response includes a URL with the attachment ID.
There is a one limitation. An app with delegated permissions returns HTTP 403 Forbidden when attempting to attach large files to an Outlook message that is in a shared or delegated mailbox. With delegated permissions, createUploadSession succeeds only if the message is in the signed-in user's mailbox.
Resources:
Atttach large file

Microsoft Graph API - MailboxNotEnabledForRESTAPI 404 error on beta/users/{id}/photo

I am trying to fetch users profile photo using the beta endpoint beta/users/{id}/photo of the Microsoft Graph API
but I get a 404 MailboxNotEnabledForRESTAPI error
error: {
code: 'MailboxNotEnabledForRESTAPI',
message: 'REST API is not yet supported for this mailbox.'
...
The error does not make sense because I am trying to access Azure Ad profile picture which should not have anything to do with mailbox.
Would anyone know if I am missing something?
The endpoint you're using says the following about getting a user picture:
Note: When attempting to GET a user photo, this operation first attempts to retrieve the specified photo from Microsoft 365. If the photo is not available in Microsoft 365, the API attempts to retrieve the photo from Azure Active Directory.
Historically the user profile picture was stored in the Exchange server, apparently they are now also saving the image somewhere else.
To check your issue, I've added a picture to a user that doesn't have any license. And started trying requests in the Graph Explorer
Request to v1.0/users/upn_here/photo ❌ failed with ResourceNotFound -> Resource could not be discovered.
Request to beta/users/upn_here/photo ✔ gives me information about the image (eg. size)
Request to v1.0/users/upn_here/photo/$value ❌ failed with ResourceNotFound -> Resource could not be discovered.
Request to beta/users/upn_here/photo/$value ✔ gives me the image. (I see the picture I uploaded before).
You should check the used access token, copy the token and paste it here https://jwt.ms (Microsoft owned page to show you the data in the token).
According to the docs you'll need at least the delegated User.Read scope or the application scope User.Read.All.

Uploading a large attachment using Microsoft Graph

I am trying to upload a large (> 4mb) attachment to an existing message in Office 365. I am following these instructions: https://learn.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http
I have successfully created the upload session, and obtained a uploadUrl value that looks legitimate, it roughly matches the example in the documentation. Then I start my PUT to this url, for the first byte range that I've selected. I'm sure I'm setting the Content-Type, Content-Length and Contact-Range headers correctly. My problem is that I get http 401 (Unauthorized) in response. The error header returned is "The audience claim value is invalid for current resource..." and it regurgitates my url and it looks intact.
My theory is that I need to add another API permission to my application. I already have mail read.write, and that allows me to create a < 4mb attachment. If I need another permission, which one? Or do I have some other problem?
According to this documentation page on Resumable Uploads, you'll need any of Files.ReadWrite, Files.ReadWrite.All or Sites.ReadWrite.All permissions for a Delegated Work account.
If you're using an Application token, then you need Sites.ReadWrite.All permission.
What were the permissions you were missing that you had to add out of interest? Was the docs clear from our perspective? I can see the Resumable file upload permissions is specific to SharePoint and can use "Files.ReadWrite, Files.ReadWrite.All, Sites.ReadWrite.All".
For mail message you'd need Mail.ReadWrite as per this doc for large file upload https://learn.microsoft.com/en-us/graph/api/message-post-attachments?view=graph-rest-1.0&tabs=http
I've created a feedback item on the doc to get this updated. https://github.com/microsoftgraph/microsoft-graph-docs/issues/6817

Slack image url asks for login

I have integrated slack in my custom application using the API provided by Slack.
I am able to fetch the post from Slack and able to display it in my application. I am able to fetch the image that was uploaded with the post (Few days back) but today when I added a post with the image. The image is not being displayed in the application, when I am trying to access the image URL in the browser it is asking for Authentication.
I am accessing the slack rest API to fetch the post from slack. from the response I am taking the "thumb_64" parameter from the "file" object.
I am able to access the below image URL, this image was uploaded on 2016-01-11
https://files.slack.com/files-tmb/T0F8RH7U7-F0J505EG1-33434fadf3/screenshot_from_2015-12-28_15_23_39_160.png
But I am not able to access the below mentioned URL ,this image is uploaded on 2016-02-16
https://files.slack.com/files-tmb/T0F8RH7U7-F0MHZL70Q-d740ed784b/configration_160.png
Thanks & Regards,
Have you seen the update where #slackapi announced about accessing files using the Web API?
Essentially, you now need to provide authentication to access file assets, by specifying an HTTP Authorization header with an OAuth token that has the correct scopes to access that kind of data for a team.
For example, you'd send a header like this with your GET request:
GET https://files.slack.com/files-tmb/T0F8RH7U7-F0MHZL70Q-d740ed784b/configration_160.png
Authorization: Bearer YOUR_VALID_ACCESS_TOKEN_HERE
The File type documentation goes into further detail.

DropBox file upload using core api https://api-content.dropbox.com/1/files/<root>/<path>

I am integrating dropbox in my app using OAuth 2.0 and now I want to upload a image using it's core api
https://api-content.dropbox.com/1/files//
my problem is there is no parameter shown for file upload (where i can send NSData)
DropBox documentation link :- https://www.dropbox.com/developers/core/docs ( /files (POST) )
I don't want to upload file/image using DBRestClient because it requires two time of login one via webView (OAuth 2.0) and another one via it's internal framework and my app require OAuth 2.0 integration.
Look closer. The documentation says:
Request body: "The file contents to be uploaded. Since the entire POST body will be treated as the file, any parameters must be passed as part of the request URL. The request URL should be signed just as you would sign any other OAuth request URL."
So you need to upload the actual contents through the message body (where the POST data would go).
However, the documentation also recommends to use /files_put instead.

Resources