This class helps you to create a REST response to a scripted REST API Request.

Objects of this type cannot be instantiated and created automatically. They are accessible within the API action script body by the request variable. 

For more information, please refer to the Configuring Scripted REST API article.

setBody(body)


This method returns the body content within the REST response. Response body is returned in JSON format.


Parameter:

NameTypeMandatoryDefault Value
bodyObjectYN
bodyStringYN

Example:

setBody
(function (request, response) {
  response.setBody({
    "status": "ok",
    "support_phone": ss.getProperty('simple.auth_page.support_phone')
  });
})(SimpleApiRequest, SimpleApiResponse)

setHeader(header, value)


This method allows to set a value to a REST response header. 

Parameters:

NameTypeMandatoryDefault Value
headerStringYN
valueStringYN

Example:

setHeader
(function (request, response) {
  response.setHeader('BACKEND-VERSION', ss.getProperty('simple.version.back'));
  response.setHeader('FRONTEND-VERSION', ss.getProperty('simple.version.front'));
})(SimpleApiRequest, SimpleApiResponse)

setHeaders(headers)


This method allows to define headers for REST response.

Parameters:

NameTypeMandatoryDefault Value
headersObjectYN

Example:

setHeaders
(function (request, response) {
  response.setHeaders({
    'BACKEND-VERSION': ss.getProperty('simple.version.back'),
    'FRONTEND-VERSION': ss.getProperty('simple.version.front')
  });
})(SimpleApiRequest, SimpleApiResponse)

setStatus(status)


This method sets the HTTP status code number for the service response. To get the information about status code returned, please refer to the status code list.

For example, the status code 200 is for success, and the status code 404 denotes that the requested URI was not found.

Parameters:

NameTypeMandatoryDefault Value
StatusIntegerYN

Example:

setStatus
(function (request, response) {
  response.setBody({
    "support_phone": ss.getProperty('simple.auth_page.support_phone')
  });
  response.setStatus(200);
})(SimpleApiRequest, SimpleApiResponse)

  • No labels