0
votes

Using the Microsoft graph API, I'm getting webhook notifications for each MS Teams message. When a message with a file attachment is received in the following format:

"attachments": [
    {
        "id": "aa567f71-4702-4b43-b756-2f453ddb662a",
        "contentType": "reference",
        "contentUrl": "... the url",
        "content": null,
        "name": "my file.xlsm",
        "thumbnailUrl": null
    }
],

I'm trying to then call the graph API to retrieve the file information and perform operations on it (specifically delete) using the id above (https://graph.microsoft.com/v1.0/groups/" + teamId + "/drive/items/" + id) and getting an error (The resource could not be found). I'm guessing that the id I'm getting in the attachment isn't the file item ID. Is there a way I can get the item ID from the attachment ID using the graph API?

1
Could you please take a look at List driveItems using Graph API? To get attachment in Group you can follow this.Trinetra-MSFT

1 Answers

0
votes

The ID what we receive in the attachment response is actually etag id and except for downloading the content directly, we would not be able to use that at all.

There are possibly 2 ways to retrieve file metadata information.

  1. Search tag As part of the resource data what you receive, you would have received the teams or user id. You can create a request url as: /groups/<team-id>/drive/root/delta?search(q='<attachment-name>')

The above query is not reliable and it might take anywhere from 2-5 mins based on how fast MS can index it.

  1. Filter tag The other method which I currently do is get the folder id using "filesFolder" query and then get the file metadata using filter odata tag.

Example: /teams/<team-id>/channels/<channel-id>/filesFolder?$select=id <-- gets you folder id of the channel.

Using the above id, we can do the foll. /groups/<team-id>/drive/item/folder-id/children?filter=name eq 'attachment_name'