Integrating an API with Credentials

sakshi18
Tera Contributor

Greetings,

We have a requirement in Crisis module where, 

1. An API of an external source is supposed to be configured to bring in Feeds for the Crisis Map.

2. But this API has a Credentials based access which should be used to fetch data.

-- I have tried creating REST call (Flow Action) but I'm unable to figure out the actual process of sending the authentication link and details, and then sending the actual link from where the details are supposed to be fetched.

 

I have tried the below code on background script but it is giving me details of only one alert.

 

var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('POST');
var authURL = '<email for authentication>'; //basically the login page link
request.setEndpoint(authURL);
request.setRequestHeader("Content-Type", "application/json"); // supposed to be fetched in JSON format
var bodyobj = {
    "username": "<username>",
    "password": "<password>"
};
bodyobj = JSON.stringify(bodyobj);

request.setRequestBody(bodyobj);
var response = request.execute();
var getBody = response.getBody();
var httpResponseStatus = response.getStatusCode();
gs.print(httpResponseStatus);
var GetAzureAD = JSON.parse(getBody);
gs.print(JSON.stringify(GetAzureAD));
var access_token = GetAzureAD.accessToken;
gs.print('access_token:'+access_token);

//assign card

var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('GET');
var assignURL = '<links of the page from where alerts are supposed to be coming>';
request.setEndpoint(assignURL); //QA URL to be changed

request.setRequestHeader("Authorization", 'Bearer ' + access_token);

//request.setQueryParameter("psno",psno);


var response = request.execute();
var getBody = response.getBody();
var httpResponseStatus = response.getStatusCode();
gs.print('Status:'+httpResponseStatus);
var GetAzureAD = JSON.stringify(getBody);
gs.print(GetAzureAD);

 

I want help in finding a way to configure the API with credentials, so that the data can flow in properly.

Regards,

Sakshi.

 

0 REPLIES 0