Explicitly set a POST request.
Use a different url.
Use a payload.
I haven't tested the following code, but I made some changes that needed to be done.
function addUser(firstName, lastName) {
var domainURL,options,url,user;
user = {};
user.primaryEmail = firstName + "." + lastName + "@" + domainURL;
givenName: firstName,
familyName: lastName
}
user.password = Math.random().toString(36);
options = {};
options.method = "POST";
options.muteHttpExceptions = true;//Make sure this is always set
options.headers = {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
options.payload = user;
var response = UrlFetchApp.fetch(url, options);
if (response && response.getResponseCode() !== 200) {//There should always be a response unless the
//Fetch call failed and if that happens then the outer try - catch can handle it
//Handle the error here
return false;
}
response = response.getContentText();
Logger.log(response)
return true;
/*