C# Graph API TranslateExchangeIds().PostAsync() HTTP Method not allowed

Viewed 348

I am using the C# package to Microsoft Graph API. I can read messages from the Graph API. Now I'd like to translate the message IDs like shown here: https://docs.microsoft.com/de-de/graph/api/user-translateexchangeids?view=graph-rest-1.0&tabs=csharp

var translatedIds = client.Users[firstMailboxElement.SourcePostbox]
  .TranslateExchangeIds(toBeTranslated, ExchangeIdFormat.RestImmutableEntryId, ExchangeIdFormat.RestId)
  .Request()
  .PostAsync()
  .Result;

When I do so I get the following Exception:

System.AggregateException
One or more errors occurred. 
(Code: Request_BadRequest Message: Specified HTTP method is not allowed for the request target. 
Inner error: AdditionalData: date: 2021-12-15T06:52:45 [...])

Which does not seem to make sense, since I cant change the HTTP Method.

Any ideas how to fix this?

2 Answers
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "your_tenant_name.onmicrosoft.com";
var clientId = "azure_ad_app_client_id";
var clientSecret = "client_secret";
var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(
    tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var inputIds = new List<String>()
{
    "asdf"
};
var sourceIdType = ExchangeIdFormat.RestId;
var targetIdType = ExchangeIdFormat.RestImmutableEntryId;
var res = graphClient.Users["user_id"].TranslateExchangeIds(inputIds, targetIdType, sourceIdType).Request().PostAsync();
var a = res.Result;

enter image description here

I figured out, that the firstMailboxElement.SourcePostbox was null, when the exception occoured. So the call went to client.Users[null], so the request URL was incomplete.

Related