php - Zscaler API Example Code -


i have been trying connect zscalershift api: https://api.zscalershift.net/ able use web based swagger style api calls, struggling things working in postman or php. figure others have issue , thought worthwhile post online.

ok, here example code of how authenticate api, add site using function in php or update location using function.

$zscaleruser = 'username'; $zscalerpass = 'password'; $customerid = 'customerid'; $sitename = 'sitename'; $zslocid ='locationid'; $zsipaddr = 'ipaddress';  $zscalerauthcurl = zscalersignin($zscaleruser,$zscalerpass); zscaleraddlocation($zscalerauthcurl,$customerid,$sitename,$zsipaddr); zscalerupdatelocation($zscalerauthcurl,$customerid,$sitename,$zslocid,$zsipaddr);   function zscalersignin($zscaleruser,$zscalerpass) {     $curl = curl_init();      curl_setopt_array($curl, array(         curlopt_url => "https://api.zscalershift.net/shift/api/v1/signin",         curlopt_returntransfer => true,         curlopt_post => true,         curlopt_cookiesession => true,         curlopt_cookiejar => 'myjar',         curlopt_cookiefile => 'cookie',         curlopt_postfields => "username=$zscaleruser&password=$zscalerpass",         curlopt_httpheader => array(             "content-type: application/x-www-form-urlencoded"         ),     ));      $zscalerauthresponse = curl_exec($curl);     $err = curl_error($curl);      if ($err) {         echo "curl error #:" . $err;     } else {         $zscalerauthdecoded = json_decode($zscalerauthresponse, true);         print_r($zscalerauthdecoded);         //echo $zscalerauthdecoded['z-auth-token'];         return($curl);     } }  function zscaleraddlocation($zscalerauthcurl,$customerid,$sitename,$zsipaddr) {     curl_setopt_array($zscalerauthcurl, array(         curlopt_url => "https://api.zscalershift.net/shift/api/v1/admin/customers/$customerid/locations",         curlopt_returntransfer => true,         curlopt_encoding => "",         curlopt_maxredirs => 10,         curlopt_timeout => 30,         curlopt_http_version => curl_http_version_1_1,         curlopt_customrequest => "post",         curlopt_postfields => "{             \"ipaddresses\": [\"$zsipaddr\"],             \"locationtype\": \"static\",             \"name\": \"$sitename\",             \"tagassociations\": [\"profiletag\"]         }",         curlopt_httpheader => array(             "accept: */*",             "content-type: application/json"         ),     ));      $response = curl_exec($zscalerauthcurl);     $err = curl_error($zscalerauthcurl);      if ($err) {         echo "curl error #:" . $err;     } else {         $decoded_response = json_decode($response, true);         print_r($decoded_response);     } }   function zscalerupdatelocation($zscalerauthcurl,$customerid,$sitename,$zslocid,$zsipaddr) {     curl_setopt_array($zscalerauthcurl, array(         curlopt_url => "https://api.zscalershift.net/shift/api/v1/admin/customers/$customerid/locations/$zslocid",         curlopt_returntransfer => true,         curlopt_encoding => "",         curlopt_maxredirs => 10,         curlopt_timeout => 30,         curlopt_http_version => curl_http_version_1_1,         curlopt_customrequest => "put",         curlopt_postfields => "{             \"name\": \"$sitename\",             \"ipaddresses\": [\"$zsipaddr\"]         }",         curlopt_httpheader => array(             "accept: */*",             "content-type: application/json"         ),     ));      $response = curl_exec($zscalerauthcurl);     $err = curl_error($zscalerauthcurl);      if ($err) {         echo "curl error #:" . $err;     } else {         $decoded_response = json_decode($response, true);         print_r($decoded_response);     } }   ?> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -