Zum Hauptinhalt wechseln
Adaptive Planning
ai.https

ai.https

Request

Method
Description
request(url, method, body, headers, ) allowAutoRedirect)
Makes a HTTPS request. Returns a response.
As of 2018.3, request(method) supports
  • GET: Retrieve data.
  • POST: Submit data to the specified resource.
  • PUT: Creates/Replaces the specified resource.
  • PATCH: Apply partial modifications to the resource.
requestStream(url, method, body, headers
available with 2018.3
Makes a HTTPS stream request. Returns a response.
  • GET: Retrieve data.
  • POST: Submit data to the specified resource.
  • PUT: Creates/Replaces the specified resource.
  • PATCH: Apply partial modifications to the resource.
authorizedRequest(url, method, body, headers)
Makes an https request with authorization header generated for an OAuth enabled CCDS. Returns a response.
Uses the underlying OAuth configuration item details along with authorization information from the data source to generate the authorization header for the https request.
As of 2018.3, authorizedRequest(method) supports
  • GET: Retrieve data.
  • POST: Submit data to the specified resource.
  • PUT: Creates/Replaces the specified resource.
  • PATCH: Apply partial modifications to the resource.
requestAuthorizedStream(url, method, body, headers)
available with 2018.3
Makes an HTTPS stream request with authorization header generated for an OAuth enabled CCDS. Returns a response.
Uses the underlying OAuth configuration item details along with authorization information from the data source to generate the authorization header for the https stream request.
RequestAuthorizedStream(method) supports
  • GET: Retrieve data.
  • POST: Submit data to the specified resource.
  • PUT: Creates/Replaces the specified resource.
  • PATCH: Apply partial modifications to the resource.

Response

Method
Description
getHttpCode()
Returns the HTTP code of the response. For a complete list of HTTP response codes click here.
getHeaders()
Returns the response headers.
getBody()
Returns the response content.

Examples

ai.https.request
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/get?foo1=bar1&foo2=bar2'; var method = 'GET'; var body = ''; var headers = null; //ai.https.request var response = ai.https.request(URL, method, body, headers); var responseCode = response.getHttpCode(); if (responseCode == 200) { ai.log.logInfo('Test Connection Succeeded','Response code was 200'); return true; } else{ ai.log.logInfo('Test Connection Failed','Response code was not 200'); return false; } }
ai.https.requestStream
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/get?foo1=bar1&foo2=bar2'; var method = 'GET'; var body = ''; var headers = null; var response = ai.https.requestStream(URL, method, body, headers); return true; }
ai.https.authorizedRequest
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/basic-auth'; var method = 'GET'; var username='postman'; var pwd='password'; var body = '<username>'+username+'</username><password>'+pwd+'</password>'; var headers = {'Authorization': 'Basic cG9zdG1hbjpwYXNzd29yZA=='}; var response = ai.https.authorizedRequest(URL, method, body, headers); var responseCode = response.getHttpCode(); ai.log.logInfo(responseCode); if (responseCode == 200) { ai.log.logInfo('Test Connection Succeeded','Response code was 200'); var responseBody = response.getBody(); ai.log.logInfo(responseBody); //{"authenticated":true} return true; } else{ ai.log.logInfo('Test Connection Failed','Response code was not 200'); return false; } }
ai.requestAuthorizedStream
function testConnection(context) { //This example connects to Postman Echo using GET var URL = 'https://postman-echo.com/basic-auth'; var method = 'GET'; var username='postman'; var pwd='password'; var body = '<username>'+username+'</username><password>'+pwd+'</password>'; var headers = {'Authorization': 'Basic cG9zdG1hbjpwYXNzd29yZA=='}; var response = ai.https.requestAuthorizedStream(URL, method, body, headers); }