Using C# Dotnet 7 code that calls GraphAPI v5.x, I create a new AppReg in Azure with the necessary information, and this works perfectly. I then try to add a ClientSecret to my new AppReg using the command from the Microsoft site
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Applications.Item.AddPassword.AddPasswordPostRequestBody
{
PasswordCredential = new PasswordCredential
{
DisplayName = "Password friendly name",
},
};
var result = await graphClient.Applications["Myapplication-id"].AddPassword.PostAsync(requestBody);
I get the error code : {"Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown."}
I extract the code and message from the catch and obtain the following information:
Error.Code = Request_ResourceNotFound
Error.Message = Resource 'Myapplication-id' does not exist or one of its queried reference-property objects are not present.
As soon as you try to access or modify information using the following code:
var result = await graphClient.Applications["Myapplication-id"].xxxx => any method
I'm getting the same error. I have repeatedly checked the validity and accuracy of the value of the Myapplication-id, it's a good one.
Has anyone ever solved this problem?
I tried to load the info on my appreg via this
var result = await graphClient.Applications.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Filter = "appId eq 'Myapplication-id'";
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.QueryParameters.Top = 1;
requestConfiguration.QueryParameters.Orderby = new string[] { "displayName" };
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
I can see all the properties and add a password like this :
Application requestBody = new()
{
PasswordCredentials = new List<PasswordCredential>
{
new()
{
DisplayName = "Password friendly name",
StartDateTime = DateTimeOffset.Now.AddYears(2),
KeyId = Guid.NewGuid()
}
}
};
var result = await graphClient.Applications["Myapplication-id"].PatchAsync(requestBody);
same result, nothing !