Mangesh Mandavgane
Mangesh Mandavgane

Reputation: 360

Google app-engine updating user information getting error 400 BAD_REQUEST

While updating user information using Directory API of Admin SDK getting an error :

400 BAD_REQUEST

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid Input: Bad request for ",
    "reason" : "invalid"
  } ],
  "message" : "Invalid Input: Bad request for "
}

Trying to update organizations details for user the fields like name, title and department

My sample code : `

Get users = directoryService.users().get(userEmail);
User user = users.execute();
try{
    List<UserOrganization> userOrg = new ArrayList<UserOrganization>();
    userOrg = user.getOrganizations();
    if(userOrg != null){
        UserOrganization f_userOrg = new UserOrganization();
        f_userOrg = userOrg.get(0);
     if(f_userOrg != null){
            f_userOrg.setTitle("SAP Asso");
            f_userOrg.setName("xyz company name");
            f_userOrg.setDepartment("xyz dept name");
            f_userOrg.setType("work");
            userOrg.add(f_userOrg);
            user.setOrganizations(userOrg);
        }
    }
    InputStream body =  directoryService.users().update(userEmail,user).executeAsInputStream();
// @ this line it throws exception 400 BAD_REQUEST 
}catch(Exception e){
        e.printStackTrace();
    }

I refer this update_user link for updating user data.

Any Help will be appreciated. Thanks.

Upvotes: 5

Views: 1114

Answers (2)

Harshal Patil
Harshal Patil

Reputation: 6759

400 BAD_REQUEST is the request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

So basically there is mismatch of parameter while API call. In this case your request goes to the server but due to wrong request parameter it gives 400 error.

Upvotes: 1

BoringProgrammer
BoringProgrammer

Reputation: 101

Can you print the request that you are sending to Google API. There can be a problem with the format that you are sending.

Upvotes: 2

Related Questions