varlib=require('./libs/helpers');functionmain(text,auth){/* BASIC GET API call */vargetUrl='https://api.your.com/v1/object';vargetHeaders={};getHeaders['authType']='API';print(getUrl);vargetResponse=lib.get(getUrl,getHeaders);print(JSON.stringify(getResponse));}
calling an API (GET) using a BASIC authentication
varlib=require('./libs/helpers');functionmain(text,auth){/* BASIC GET API call */vargetUrl='https://api.your.com/v1/object';vargetHeaders={};getHeaders['authType']='BASIC';getHeaders['username']=msg.basicUsername;getHeaders['password']=msg.basicPassword;print(getUrl);vargetResponse=lib.get(getUrl,getHeaders);print(JSON.stringify(getResponse));}
calling an API (POST/GET) using an OAUTH2 authentication
varlib=require('./libs/helpers');functionmain(text,auth){varshare=lib.parseMsg(text);/* OAUTH2 POST API call */varpostUrl='https://api.your.com/v1/object';varpostHeaders={};postHeaders['authType']='OAUTH2';postHeaders['token']=msg.oauthToken;postHeaders['contentType']='application/json';// Body from JSON Stringvarbody1='{\"test\":\"data\"}';// Body from triggering sharevarbody2=JSON.stringify(share.objs[0].data);varpostResponse=lib.post(postUrl,postHeaders,JSON.parse(body2));print(JSON.stringify(postResponse));/* OAUTH2 GET API call */vargetUrl='https://api.your.com/v1/object';vargetHeaders={};getHeaders['authType']='OAUTH2';getHeaders['token']=msg.oauthToken;vargetResponse=lib.get(getUrl,getHeaders);print(JSON.stringify(getResponse));}
calling an API (GET) using a CUSTOM authentication