How download a chat attachment without contentUrl

Fabio Fornaciari 31 Reputation points
2023-04-03T14:02:57.54+00:00

Hi,

I have a problem with a chat message received by a personal user account ( therefore different tenant from mine ) with an attachment (I am a business account user).
This is the relevant part of the json object got by GraphAPI ( v1.0/me/chats/<chatId>/messages/<messageId> ) of the chat message I received:

...

 "from": {
                "application": null,
                "device": null,
                "user": {
                    "@odata.type": "#microsoft.graph.teamworkUserIdentity",
                    "id": "<name>.<surname>_3",
                    "displayName": "<Name> <Surname>",
                    "userIdentityType": "personalMicrosoftAccountUser"
                }
            },
            "body": {
                "contentType": "text",
                "content": "File zip<attachment id=\"b9cbc7dc8d1a3ef3!342\"></attachment>"
            },
            "attachments": [
                {
                    "id": "b9cbc7dc8d1a3ef3!342",
                    "contentType": "reference",
                    "contentUrl": null,
                    "content": null,
                    "name": "Test file 8.zip",
                    "thumbnailUrl": null,
                    "teamsAppId": null
                }
            ],

...

As you can see inside the property "attachments", "contentUrl" is null and I don't know how get the attachment file by id.
I am not able to find the file inside my oneDrive or shared with me or in hostedContents of the chat.
I see that the attachment id seems like a drive item,
but calling the GraphAPI .../drives/b9cbc7dc8d1a3ef3/items/b9cbc7dc8d1a3ef3!342
I receive an error:

 "error": {
        "code": "invalidRequest",
        "message": "The provided drive id appears to be malformed, or does not represent a valid drive.",

Also calling the GraphAPI .../users/<id>/drives (with the userId I received from chats/<chatId>/members API) to see the drive list of the other user I got an error:

"error": {
        "code": "ResourceNotFound",
        "message": "User not found",

How can I get this file?

I am able to download it only throught the MsTeams app, and i see that like a link to OneDrive app:
https://1drv.ms/u/s!<alphanumeric_code>

that redirect me to this page:
https://onedrive.live.com/?authkey=<authKey>&id=B9CBC7DC8D1A3EF3%21342&cid=B9CBC7DC8D1A3EF3&parId=root&parQt=sharedby&o=OneUp

I can understand that the attachment id is the same queryString param "id" and the queryString param "cid" is the attachment id without the last part "!<number>".

How can I build/create by my self the <alphanumeric_code>?
Or how can I build/retrieve the <authKey> value?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,445 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,711 Reputation points Microsoft Vendor
    2023-04-06T09:52:15.6933333+00:00

    Hello @Fabio Fornaciari , Using GET /me/chats/{chat-id}/messages/{message-id}, I am able to see the contentUrl property. Graph API call made using work account and chat message sent by personal Microsoft Account to work account. Graph_Chat_Message

    By design, if a OneDrive personal user shares a file, it will not be visible in OneDrive for business (work or school account) shared with me. And thus, you will not be able use Graph API to get the same.

    When you click on file teams chat message, you are actually clicking on 1drv.ms sharing link which validates the user identity and will be able to access the same.

    When using users/{userid} with work account it is expected to get User not found error as the personal account is not found in Azure AD of the organization.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments