I'm trying to remove a Home Page URL from an Azure App Registration using Graph Rest API following MS Doc https://learn.microsoft.com/en-us/graph/api/application-update?view=graph-rest-1.0&tabs=http
Graph Does not throw any exceptions when I am passing null. Returning 204. However, Home Page URL is not removed.
If I am passing empty string, Graph throwing exceptions which is valid .
var updateApp = new Application
{
Web = new WebApplication
{
HomePageUrl = null
},
};
await graphClient.Applications[applicationObjectId].Request().UpdateAsync(updateApp);
Can someone help me how to remove existing Home Page URL using Graph in C#?
Note that, there will be a slight delay in Portal to reflect the changes after running the code.
I registered one Azure AD application and added sample Home Page URL as below:
To remove this existing Home Page URL using Graph in C#, I ran below code:
using Azure.Identity;
using Microsoft.Graph;
using Microsoft.Graph.Models;
using Microsoft.Graph.Models.ODataErrors;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var clientId = "appId";
var tenantId = "tenantId";
var clientSecret = "secret";
var options = new ClientSecretCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var updateApp = new Application
{
Web = new WebApplication
{
HomePageUrl = null,
},
};
try
{
var result = await graphClient.Applications["appObjectId"].PatchAsync(updateApp);
Console.WriteLine("Home Page URL removed successfully");
}
catch (ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
throw;
}
Response:
When I checked the same in Portal after few minutes by refreshing the page, Home Page URL removed successfully in the application as below: