0
votes

Is it possible to create users in bulk via the REST API. Same as we do for single user in the below URL.

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

We have the provision via the Azure portal but could'nt find anything with REST API.

UPDATED Sample request for Batch processing

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

1 Answers

0
votes

Yes. You can batch operations by referring to Batch processing | Graph API concepts.

But we recommend you use Microsoft Graph API JSON Batching instead of Azure AD Graph Batch processing because Azure AD Graph content is no longer updated.

An example using Microsoft Graph API here:

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"
      }
    }
  ]
}

You can have a quick test in Microsoft Graph Explorer.