Pieterjan Buydens
Pieterjan Buydens

Reputation: 21

Issue Accessing Google Admin SDK API from Google Apps Script

Hello StackOverflow community,

I am currently facing an issue while attempting to access the Google Admin SDK API from within a Google Apps Script. Specifically, I am encountering an error when trying to add a mailaddress to a Google Group using the following JavaScript function:

function addGroupMemberV2(mailArr, groupkey, type) {
  let requests = [];

  mailArr.forEach((userEmail) => {
    let member = {email: userEmail, role: type};
    member = JSON.stringify(member);

    requests.push({
      method: "POST", // Use "POST" to add a member
      endpoint: `https://admin.googleapis.com/admin/directory/v1/groups/${groupkey}/members`,
      payload: {
        member: member
      }
    });
  });

  try {
    return batchRequest(requests, "batch/admin/directory_v1");
  } catch (e) {
    Logger.log(e);
  }
}`

The error message I am receiving is as follows:

[{error={code=400.0, message=Missing required field: member, errors=[{domain=global, reason=required, message=Missing required field: member}]}}]

I want to clarify that I am attempting to make this REST API call from within a Google Apps Script. I have ensured that the "member" field is included in the payload, but it seems there might be an issue with the way I am accessing the Admin SDK API from Google Apps Script.

I would greatly appreciate any insights or guidance on how to resolve this issue. Thank you for your help!

I've experimented with various approaches to make the REST API call. I attempted renaming the payload to 'data', but none of these attempts proved successful.

Upvotes: 0

Views: 46

Answers (0)

Related Questions