1

I am trying to make a POST request to this url: https://www.googleapis.com/admin/directory/v1/customer/***/orgunits in order to create new Organizational Units.

This is the code to make a cURL request:

    function exeCurl($url,$method,$body="") {
 $curl = curl_init();


curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 40,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => $method,
    CURLOPT_HTTPHEADER => array(
    //    "Accept: */*",
    //    "Accept-Encoding: gzip, deflate",
        "Authorization: Bearer ". $_COOKIE["LOStoken"],
     //   "Cache-Control: no-cache",
         "Content-Type: application/json",
        //"Connection: keep-alive",
        "Content-Length: ". strlen($body),
       // "Host: www.googleapis.com",

       // "cache-control: no-cache"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

}

Ive played around with enabling / disabling several headers but with no success. This is the call to exeCurl:

 function createOU($createOUname, $parentOUpath, $description) {

    echo $createOUname;
    echo $parentOUpath;
    echo $description;
    $body = array(
        "name" => $createOUname,
        "description" => $description,
        "parentOrgUnitPath" => $parentOUpath
    );

    $ou = new \Google\OU();

    echo $ou->exeCurl("https://www.googleapis.com/admin/directory/v1/customer/***/orgunits","POST",json_encode($body));

}

(with *** being my customer ID)

it gets the values of Html input fields.

I cannot figure why its not working. I also have tried putting timout to 0. I tried to make a POST request with Postman with the same values and its working there.

Y_Lakdime
  • 825
  • 2
  • 15
  • 33

0 Answers0