I have a user in my google admin console with the email dog@jopfre.com. I can auth successfully and add and delete users using the api. Now I am trying to update the user using the api. Here is a simplified version of my code:
const admin = google.admin({version: 'directory_v1', auth});
admin.users.update({
userKey: "dog@jopfre.com",
requestBody: {
primaryEmail: "cat@jopfre.com"
}
},(err, data) => {
console.log(err || data);
});
This returns json of the request and a 200 status.
The nearest example I can find in the docs is this:
admin.members.insert({
groupKey: 'my_group@example.com',
requestBody: { email: 'me@example.com' },
auth: jwt
}, (err, data) => {
console.log(err || data);
});
So it looks pretty similar to me.
I have tried with and without quotation marks on the requestBody key and have also tried updating different key values like givenName
and suspended
. I'm guessing my request is malformed somehow but I can't work out how as no error is returned.
Any clue or ideas of what to try next?
Here are some of the more relevant lines from the returned json:
status: 200,
params: { requestBody: { primaryEmail: 'cat@jopfre.com' } },
_hasBody: true,
header: 'PUT /admin/directory/v1/users/dog@jopfre.com?requestBody%5BprimaryEmail%5D=cat%40jopfre.com HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: Bearer ya29.GlwXBi796knRrOTbzvJ1ihzBaQqHKk3HYA9-3pxUgCxaCvPKxZLYGRrghq_RcFHbZYqyKEqUV6yOWusBui2Vh1DLd50MsKQ5o4MoqzutVr8P280ULY2cYzSYLtGOyw\r\nUser-Agent: google-api-nodejs-client/1.6.1\r\nHost: www.googleapis.com\r\nConnection: close\r\nContent-Length: 0\r\n\r\n',
path: '/admin/directory/v1/users/dog@jopfre.com?requestBody%5BprimaryEmail%5D=cat%40jopfre.com',
responseUrl: 'https://www.googleapis.com/admin/directory/v1/users/dog@jopfre.com?requestBody%5BprimaryEmail%5D=cat%40jopfre.com',
_requestBodyLength: 0,
Not sure if the requestBodyLength should be 0, that seems off.