Sunteți pe pagina 1din 2

API

Specs


API_Utils is a script include that contains various useful functions to create scripted rest api. Below is
the list of those functions that can be used while creating scripted rest api(s).

1. checkMandatoryFields
Return error message if all required fields has not been provided in request header as well as in query
parameters.
checkMandatoryFields (Boolean queryParm, Boolean headerParm, RESTAPIRequest request, RESTAPIRespo
nse response, String APIName /*API Resource Name*/)

Return: empty string ()/error response IFF all the required fields (Query Parameters as well as Request
Headers) has been provided.

Example:
var _mandatoryFieldsChecker = new global.API_Utils().checkMandatoryFields(true, true, request, response,
"sample single record");
if (_mandatoryFieldsChecker! ="")
{
return _mandatoryFieldsChecker;
}

2. checkTable
Return error message if table name (input key) is provided and there exists a mapping between
provided key and SN actual table.

checkTable (String Table, String APIName /*API Resource Name*/, RESTAPIResponse response)

Return: empty string () IFF there exists a relationship between provided key and SN actual table

Example:
var checkResponse = new global.API_Utils().checkTable(inc, 'sample single record', response);
if (checkResponse! ="")
{
return checkResponse;
}

3. getTableName
Returns actual table name for provided input key that exists in u_api_specs table.

getTableName (String Table, String APIName /*API Resource Name)

Example:
var _tableName = new global.API_Utils().getTableName(inc, 'sample single record');

4. getAllData

Returns RESTAPIResponse object (array data in JSON format) for defined fields in u_api_specs_details
table for particular API Resource (e.g. sample incidents).

getAllData (String Table, String query /*Encoded Query String*/, String API Resource Name /*API Resource
Name*/, RESTAPIResponse response)

Example
new global.API_Utils().getAllData(incident/*actual table name */, "" /*Encoded query string*/, 'sample in
cidents' /*API Resource Name*/, response );

5. getRecord

Returns RESTAPIResponse object (all data in JSON format) for defined fields in u_api_specs_details
table for particular API Resource (e.g. sample incidents).

getRecord (String Table, String query /*Encoded Query String*/, String API Resource Name /*API Resource N
ame*/, RESTAPIResponse response)

Example
new global.API_Utils().getRecord(incident/*actual table name*/ , "number=INC10001001 , 'sample chan
ge record' , response);

6. getAttachmentByID

Returns attachment as a binary stream object for provided attachment_sys_id.

getAttachmentByID (String attachmentSysId, RESTAPIResponse response)

Example
new global.API_Utils().getAttachmentByID(_attachmentSysID, response);

Response Header: includes file_name that contains file name and file_mime that contains MIME type
of attachment.

S-ar putea să vă placă și