Hi @Kasim Sharif
Welcome to the Q&A Forum!
First of all, I am not sure if it is your writing error, /users/{user-id}/messages/{attachments}/attachments
is not a valid api endpoint, the correct endpoint should be: /users/{user-id}/messages/{message-id}/attachments
.
However, even with the correct endpoint, you cannot list specific attachments under a specific message, which returns only one collection of attachment lists. If you want to get a specific attachment under a specific message, then it may take multiple calls, because the endpoint does not appear to be able to filter using the $filter
parameter.
1. /users/<user-id>/messages/<message-id>/attachments
2. /users/<user-id>/messages/<message-id>/attachments/<attachment-id>
If you are interested in automation, then using the graph C# SDK is undoubtedly a good solution, you just need to traverse the attachment set and then make a simple judgment with a specific attachment name to get a specific attachment under a specific message:
using Azure.Identity;
using Microsoft.Graph;
using Newtonsoft.Json;
try
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "{tenant id}";
// Values from app registration
var clientId = "{client id}";
var clientSecret = "{client secret}";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var attachments = await graphClient.Users["{user name}"].Messages["message id"].Attachments.Request().GetAsync();
for (int i = 0; i < attachments.Count; i++) {
var attachmentName = attachments[i].Name;
if (attachmentName == "{attachment name}") {
Console.WriteLine("att:" + JsonConvert.SerializeObject(attachments[i]));
}
}
}
catch (Exception ex) {
Console.WriteLine(ex);
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.