Azure AD B2C REST API:创建批量本地帐户

时间:2020-03-26 07:15:20

标签: azure rest azure-active-directory

是否可以通过REST API批量创建用户。与我们在下面的URL中为单个用户所做的相同。

https://graph.windows.net/ {MYADB2C} .onmicrosoft.com / users?api-version = 1.6

我们已通过Azure门户进行了配置,但使用REST API找不到任何内容。

已更新 批处理的样品请求

POST https://graph.windows.net/{}.onmicrosoft.com/$batch?api-version=1.6
Headers :
Authorization : {token}
Content-Type : multipart/mixed; boundary=changeset_***********

Body :
{
  "requests": [
    {
      "id": "1",
      "method": "POST",
      "url": "/users",
      "body": {
        "accountEnabled": true,
        "creationType": "LocalAccount",
        "displayName": "test1@gamil.com",
        "passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
        "passwordProfile": {
          "password": "***",
          "forceChangePasswordNextLogin": false
        },
        "signInNames": [
          {
            "type": "emailAddress",
            "value": "test1@gamil.com"
          }
        ]
      },
      "headers": {
        "Content-Type": "application/json"
      }
    },
    {
      "id": "2",
      "method": "POST",
      "url": "/users",
      "body": {
        "accountEnabled": true,
        "creationType": "LocalAccount",
        "displayName": "test2@gmail.com",
        "passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
        "passwordProfile": {
          "password": "***",
          "forceChangePasswordNextLogin": false
        },
        "signInNames": [
          {
            "type": "emailAddress",
            "value": "test1@gamil.com"
          }
        ]
      },
      "headers": {
        "Content-Type": "application/json"
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

是的。您可以通过参考Batch processing | Graph API concepts来批量操作。

但是我们建议您使用Microsoft Graph API JSON Batching代替Azure AD Graph批处理,因为Azure AD Graph的内容不再更新。

在此处使用Microsoft Graph API的示例:

POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json

{
  "requests": [
    {
      "id": "1",
      "method": "POST",
      "url": "/users",
      "body": {
          "accountEnabled": true,
          "displayName": "at1",
          "mailNickname": "at1",
          "userPrincipalName": "at1@**.onmicrosoft.com",
          "passwordProfile" : {
              "forceChangePasswordNextSignIn": true,
              "password": "password-value"
          }
      },
      "headers": {
        "Content-Type": "application/json"
      }
    },
    {
      "id": "2",
      "method": "POST",
      "url": "/users",
      "body": {
          "accountEnabled": true,
          "displayName": "at2",
          "mailNickname": "at2",
          "userPrincipalName": "at2@**.onmicrosoft.com",
          "passwordProfile" : {
              "forceChangePasswordNextSignIn": true,
              "password": "password-value"
          }
      },
      "headers": {
        "Content-Type": "application/json"
      }
    },
    {
      "id": "3",
      "method": "POST",
      "url": "/users",
      "body": {
          "accountEnabled": true,
          "displayName": "at3",
          "mailNickname": "at3",
          "userPrincipalName": "at3@**.onmicrosoft.com",
          "passwordProfile" : {
              "forceChangePasswordNextSignIn": true,
              "password": "password-value"
          }
      },
      "headers": {
        "Content-Type": "application/json"
      }
    }
  ]
}

您可以在Microsoft Graph Explorer中进行快速测试。