Welcome to Microshare’s Generic REST API documentation!
This API allows you to do GET/POST calls to any endpoints/external api urls through a robot script. .
The library helper is required in the robot script to call the generic rest api functions.
var url = require('./libs/helpers’);
This is the endpoint/external api url that you want to do the GET/POST call to.
var lib = 'https://any/endpoint';
Headers is where you pass in the authorization/authentication information like auth type, creds, and content type for your GET/POST calls. Headers can also be just an empty header but it is a required parameter for both get and post.
var headers = {}; //required
The generic rest api supports three types of authentication: BASIC, OAUTH2, API. For each type different information is passed into the headers. Here is some sample code for each type below.
headers["authType"] = "BASIC";
headers["username"] = "YOUR USERNAME GOES HERE";
headers["password"] = "YOUR PASSWORD GOES HERE”;
headers["authType"] = "OAUTH2";
headers["token"] = "YOUR ACCESS TOKEN GOES HERE";
This type requires you to pass the api key information into the url directly instead.
var url = 'https://any/endpoint?apikey=MY API KEY';
Content type is another one that gets added to the headers. It can be done for two different reasons. Content type can be added for GET call in order to be able to get the return/response type in the sepcified content type. And content type can be added for POST call to specify the content type of the body/data you are sending with the post call. For both types though the content type gets added to the headers in the exact same way. Note that for the POST call the default content type is application/json.
headers["Content-Type"] = "application/json";
Body is required to be able to do POST call.
var body = ‘{"data":"test"}';
To do a get call in robot and print its response:
var response = lib.get(url, headers);
print(JSON.stringify(response));
To do a post call in robot and print its response:
var response = lib.post(url, headers, body);
print(JSON.stringify(response));