jayeshkv
jayeshkv

Reputation: 2208

Azure AD Graph API not returning User GUID for Create User

This is the URL of the post format that i am sending the request in.

https://graph.windows.net/myorganization/users?api-version=1.6

I am also attaching the Authentication header value Bearer with access token. request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

I am requesting with these elements in the body

Content-type: application/json

{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "[email protected]",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password-value"
  }
}

Source : Link

This is the response I am getting

{StatusCode: 201, ReasonPhrase: 'Created', Version: 1.1, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:
{
  Cache-Control: no-cache
  Date: Wed, 30 Aug 2017 19:11:40 GMT
  Pragma: no-cache
  Location: https://graph.windows.net/metadata/directoryObjects/metadata/Microsoft.DirectoryServices.User
  Server: Microsoft-IIS/8.5
  ocp-aad-diagnostics-server-name: servername
  request-id: req id
  client-request-id: client request id
  x-ms-dirapi-data-contract-version: 1.6
  ocp-aad-session-key: some random keys
  X-Content-Type-Options: nosniff
  DataServiceVersion: 3.0;
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Access-Control-Allow-Origin: *
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  X-Powered-By: ASP.NET
  Duration: 4425304
  Content-Length: 1271
  Content-Type: application/json; odata=minimalmetadata; streaming=true; charset=utf-8
  Expires: -1
}}

But i am unable to find any Userdata / GUID as mentioned in the Source link above.

Any help would be appreciated.

Upvotes: 3

Views: 1105

Answers (2)

RasmusW
RasmusW

Reputation: 3461

The response you posted only contains the headers. There is also a JSON body (the headers include Content-Length: 1271).

As you can see in the link you posted, the response body contains the new user information, including the user's objectId, so you should parse the body.

Upvotes: 4

Marc LaFleur
Marc LaFleur

Reputation: 33114

You're conflating Azure Active Directory Graph with Microsoft Graph API. These are two distinct APIs. While Microsoft Graph API is replacing AAD Graph, they have different methods and payload so the code is not interchangeable between the two. They also use different tokens.

When you're creating a user, you'll want to POST that JSON payload to https://graph.microsoft.com/v1.0/users not https://graph.windows.net/....

You'll also want to make sure you request the User.ReadWrite.All scope and that you're either using a Global Administrator account or have had a Global Admin go through the Admin Consent flow. This will give your the required permissions to create a user in the directory.

Upvotes: 1

Related Questions