Unable to update "manager" Azure AD attribute using microsoft graph java sdk

Praba Kar 21 Reputation points
2020-10-08T06:31:38.757+00:00

I have tried to assign manager attribute to an user object in AZURE AD using MS graph java SDK as mentioned in this URL - "https://video2.skills-academy.com/en-us/graph/api/user-post-manager?view=graph-rest-1.0&tabs=java"

CODE

DirectoryObject directoryObject = new DirectoryObject();
directoryObject.id = childObjectGUID;
graphServiceClient.users(parentObjectGuid).manager().reference().buildRequest().put(directoryObject);

But i'm getting error message as "400: Bad Request". Please find the detail error message below.

ERROR MESSAGE

Error code: Request_BadRequest
Error message: An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected.

PUT https://graph.microsoft.com/v1.0/users/ab5e1c6a-1c58-4c38-a481-6b3098004004/manager/$ref
SdkVersion : graph-java/v2.1.0
Authorization : [PII_REDACTED]
{"id":"2c77e30b-d2d0-4646-9d1b-9ffa4befcb61"}

400 : Bad Request
[...]

I can able to update other attributes like members, owners, etc.,

PERMISSIONS
30866-microsoft.png

Required permissions as been provided.

Kindly help me. Thanks in advance.

Best Regards,
Prabakaran K

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,367 questions
0 comments No comments
{count} votes

Accepted answer
  1. soumi-MSFT 11,771 Reputation points Microsoft Employee
    2020-10-08T07:39:33.85+00:00

    Hello @Praba Kar , Thank you for reaching out. I believe the following error "Error message: An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected." is coming up as you might not have supplied the payload in the body in correct format i.e:

    {  
      "@odata.id": "https://graph.microsoft.com/v1.0/users/6e821af1-5289-4011-983d-634abf48e7b7"  
    }  
    

    I tried the Postman tool to assign a manager to a user and it worked fine for me.

    30840-assignmanager.png

    You need to specify "@odata.id" as the key in the supplied JSON Body for it to work. The following line in your code graphServiceClient.users(parentObjectGuid).manager().reference().buildRequest().put(directoryObject); should send the body with the key as @odata.id. If it's not I would suggest debugging the application once and check why that @odata.id is not being sent as the JSON payload in the body of the request.

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.