Insert an Org Unit with Google Apps Script getting Bad Request error

307 views Asked by At

I have followed the API documentation to insert an org unit but I am recieving a "Bad Request" error. Here is a snippet of my code.

function orgUnitCreate() {
  var resource = {
    name: first+' '+init,
    parentOrgUnitPath: '/Students/'+unit,
    blockInheritance: false
  };
  
  AdminDirectory.Orgunits.insert(resource, "myCustomerID redacted for privacy");//This is the line throwing the error
}

Thank you for your help

edit: I did indeed have an error in my customer ID, thank you

2

There are 2 answers

0
Jose Vasquez On

This error can result from

  • A required field or parameter hasn't been provided.
  • The value supplied or a combination of provided fields is invalid.

400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error

Summary

As mentioned in the comment section, this problem might be caused by a missing/incorrect customerID.

Reference

0
Iliana Ruiz Zurita On
function orgUnitCreate() {
   var resource = {
       name: first+' '+init,
       parentOrgUnitPath: '/Students/'+unit,
       blockInheritance: false
   };
   try {
      resp= AdminDirectory.Orgunits.insert(resource, "my_customer"); 
   } catch (e) {
      resp = e; //Catch The error
   }
   Logger.log(resp);
}