简体   繁体   中英

Microsoft Graph API Create User in Azure AD gets 500 error

After successfully Authenticated using MSAL. I get the token and passed it on the Flurl. I'm getting 500 error. But if I test it on Postman it works properly. Anything I missed?

Below is my code:

    var user = new User
    {
        AccountEnabled = true,
        DisplayName = "Anthony Test",
        MailNickname = "AnthonyT",
        UserPrincipalName = "AnthonyT@*****.onmicrosoft.com",
        PasswordProfile = new PasswordProfile
        {
            ForceChangePasswordNextSignIn = true,
            Password = "xWwvJ]6NMw+bWH-d"
        }
    };

    var result2 = await "https://graph.microsoft.com/v1.0/users".WithHeader("Content-Type", "application/json")
        .WithOAuthBearerToken(result.AccessToken)
        .PostJsonAsync(user);

Here is a screenshot from Postman: 在此处输入图像描述

I have fixed the issue. I forgot to set JsonProperty and make it camelCase. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM