Uploading a large attachment using Microsoft Graph - microsoft-graph-api

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

Related

Whatsapp Cloud - Product Catalog - Batch APIs not working

We need to create, update or delete product(s) from our catalog.
For doing this programatically we are following Meta's Product Catalog Batch API documentation in which there is an endpoint mentioned as "<product_catalog_id>/batch". We are trying to make request at this endpoint by passing the payload as mentioned in the official documentation.
But I am getting "403 forbidden" error every time. On digging deeper I found that the access token which is making this API call must have 2 permission i.e. "catalog_management" and "business_management".
I have checked the access permission for my access token and it indeed has there 2 permissions.
Can anybody please help here?
I am attaching some links below, which I am using to make the batch API calls for product catalogs.
Using this link to understand the API structure = https://developers.facebook.com/docs/marketing-api/catalog-batch/guides/send-item-updates/
Using this link to make the required payload = https://developers.facebook.com/docs/marketing-api/catalog-batch/reference/
I tried generating new access tokens 2 or 3 times. I also tried changing the payload to check whether the documentation may be outdated but nothing helped me to solve this issue.
I am expecting that the product catalog batch API works, so that we can update the products from our side.

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.

Graph API - Unable to Use Valid Access Token to Upload file

I am unable to upload a file using a valid access token (the token allows me to list groups, drive items etc.). The error that appears is:
invalidRequest: One of the provided arguments is not acceptable.
Using the following PUT request:
https://graph.microsoft.com/v1.0/groups/{my group id}/drive/items/{my item(folder) id}:/test.txt:/content
using content type: text/plain
I tested this exact same request using the graph explorer https://developer.microsoft.com/en-us/graph/graph-explorer and my office 365 user account and the upload worked, so I though it might be an app permissions thing, however this did not work even after granting absolutely every permission to the app and regenerating the access tokem.
Please help as I would rather use an access token than my user account to perform the uploads.
Thankyou
Oliver
Just add a worked endpoint on my side:
PUT https://graph.microsoft.com/v1.0/groups/my-group-id/drive/root:/test.txt:/content
Request body: The contents of the file goes here.
The content type of request header does not need to be configured.
You need to check your folder path too.
I managed to resolve by creating a new app definition in Azure AD with the same permissions and it worked! Perhaps there was some corruption in my original Azure application - maybe the manifest was corrupt (due to a bug)?

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.

Resources