Forum Discussion
3 years ago
Stuart,
in my GET from them, I am passing a bearer token along with the param for our account name. Here's how I've updated my script:
import com.santaba.agent.groovyapi.http.*;
// instantiate an http client object for the target system
ip="api.ultradns.com"
httpClient = HTTP.open(ip, 443);
user = hostProps.get("ultradns.user");
pass = hostProps.get("ultradns.pass");
account = hostProps.get("ultradns.accountName");
// use an authentication API call to initiate a session
// specify the url to which we want to post
url = "https://"+ip+"/authorization/token";
def payload = '{"username":"myusername","typeId":"com.tintri.api.rest.vcommon.dto.rbac.RestApiCredentials","password":"mypassword"}';
// do the post
def postResponse = httpClient.post(url, payload,["Content-Type":"application/json"]);
// does the response indicate a successful authentication?
if ( !(httpClient.getStatusCode() =~ /200/) )
{
// no -- report an error, and return a non-zero exit code
println "authentication failure";
return(1);
}
// we are now authenticated. Subsequent GETs with the httpClient will pass in the session cookie
url="https://"+ip+"/reports/dns/usage_summary";
def getResponse=httpClient.get(url);
// print some data
println httpClient.getResponseBody();
Related Content
- 8 months ago
- 11 hours ago
- 2 years agoAnonymous
- 10 months ago