Microsoft Entra Agent ID
Developer

Create Delete Agent Identities

In brief

The documentation updates the C# sample’s imports, endpoint structure, downstream API call, and model declarations to provide valid create-agent-identity code.

What Entra admins need to know

Administrators using this sample should review the updated code. No Entra service change or administrative action is indicated.

This editorial summary was generated by AI from the documentation changes. Verify important details in the full Microsoft Learn article.

Documentation change

The comparison below shows only the changed extract. Use the full-page view for complete context.

The code for the ASP.NET Core app (Program.cs) is the following example:

using System.Text.Json.Serialization;
using Microsoft.Identity.Abstractions;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.Resource;
using Microsoft.IdentityModel.S2S.Extensions.AspNetCore;
using MyAgent;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration)
    .EnableTokenAcquisitionToCallDownstreamApi();
builder.Services.AddInMemoryTokenCaches();
var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();

public class AgentIdentity
{
    [JsonPropertyName("@odata.type")]
    public string @odata_type { get; set; } = "#Microsoft.Graph.AgentIdentity";

    [JsonPropertyName("displayName")]
    public string? displayName { get; set; }

    [JsonPropertyName("agentIdentityBlueprintId")]
    public string? agentIdentityBlueprintId { get; set; }

    [JsonPropertyName("id")]
    public string? id { get; set; }

  [JsonPropertyName("[email protected]")]
    public string[]? sponsorsOdataBind { get; set; }

  [JsonPropertyName("[email protected]")]
    public string[]? ownersOdataBind { get; set; }
}

// Create an Agent identity
app.MapGet("/create-agent-identity", async (HttpContext httpContext) =>
{
    try
    {
        // Get the service to call the downstream API (preconfigured in the appsettings.json file)
        IDownstreamApi downstreamApi = httpContext.RequestServices.GetRequiredService<IDownstreamApi>();

        // Call the downstream API with a POST request to create an Agent Identity
        var jsonResult = await downstreamApi.PostForAppAsync<AgentIdentity, AgentIdentity>(
            "agent-identity",
            new AgentIdentity
            {
                displayName = "My agent identity",
                agentIdentityBlueprintId = "<my-agent-blueprint-id>",
                sponsorsOdataBind = new []new[] { "https://graph.microsoft.com/v1.0/users/<id>" }
            }
          );});
        return jsonResult?.id;
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
});

app.Run();

// Type declarations must follow the top-level statements.
public class AgentIdentity
{
    [JsonPropertyName("@odata.type")]
    public string @odata_type { get; set; } = "#Microsoft.Graph.AgentIdentity";

    [JsonPropertyName("displayName")]
    public string? displayName { get; set; }

    [JsonPropertyName("agentIdentityBlueprintId")]
    public string? agentIdentityBlueprintId { get; set; }

    [JsonPropertyName("id")]
    public string? id { get; set; }

    [JsonPropertyName("[email protected]")]
    public string[]? sponsorsOdataBind { get; set; }

    [JsonPropertyName("[email protected]")]
    public string[]? ownersOdataBind { get; set; }
}

        options.RelativePath += $"/{id}"; // Specify the ID of the agent identity to delete
    });
return jsonResult;

});


---
Daily Entra.News

Get daily email updates

Get a concise summary of the latest Microsoft Entra updates delivered straight to your inbox.

Loading the secure signup form…