Missing required field: member

2019-07-28 10:43发布

问题:

{ errors: 
   [ { domain: 'global',
       reason: 'required',
       message: 'Missing required field: member' } ],
  code: 400,
  message: 'Missing required field: member' }

I get this error when I run the following request:

var request = client.admin.members.insert({
    groupKey: "some_group@example.com"
  , email: "me@example.com"
});

I was authenticated successfully (I received the access token and so on) but when I execute the request above it callbacks that error.

What member field am I supposed to add?

It works fine in API Explorer using groupKey and email fields.

回答1:

The documentation at https://developers.google.com/admin-sdk/directory/v1/reference/members/insert for admin.members.insert indicates that it requires a groupKey parameter, but that the body (which the node.js library handles as a separate object) should contain a members object containing the role property. See the API Explorer a the bottom of that page as well.



回答2:

email is part of the form data. The form data must be passed as object in the second argument:

// create the group insert request
var request = client.admin.members.insert({
    groupKey: "some_group@example.com"
}, {
    email: "me@example.com"
});