Skip to content

Commit 74dfb23

Browse files
authored
Aphack2023 pr (#989)
* Create script.js This fix script is used to login to API that have header as ' x-www-form-urlencoded' below script is used to login and get the token and do the operation * Create readme.md This fix script is used to login to API that have header as ' x-www-form-urlencoded' below script is used to login and get the token and do the operation
1 parent 1975f40 commit 74dfb23

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Fix scripts/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This fix script is used to login to API that have header as ' x-www-form-urlencoded' below script is used to login and get the token and do the operation

Fix scripts/script.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
This fix script is used to login to API that have header as ' x-www-form-urlencoded' below script is used to login and get the token and do the operation
3+
*/
4+
5+
(function execute(inputs, outputs) {
6+
var body = "grant_type=credentials&username=<UserName>-snow&password=<Password>";
7+
8+
try { 
9+
var r = new sn_ws.RESTMessageV2();
10+
r.setEndpoint("http:<API Endpoint Details>/api/jwt/login"); 
11+
//r.setRequestHeader("Accept", "application/json");
12+
r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
13+
r.setRequestBody(body);
14+
r.setMIDServer('Mid Server Link');
15+
r.setHttpMethod('POST'); // Post call to get the Token
16+
17+
var response = r.execute();
18+
r.setHttpTimeout(30000); // Set Time Out
19+
var responseBody = response.getBody();
20+
var httpStatus = response.getStatusCode(); // Get Status code to determine success or Faliure
21+
    gs.info("Status >>>>"+httpStatus);
22+
    gs.info("responseBody >>>>"+responseBody);
23+
outputs.token_value = responseBody;
24+
outputs.status = httpStatus;
25+
}
26+
catch(ex) {
27+
var message = ex.message;
28+
}
29+
})(inputs, outputs);

0 commit comments

Comments
 (0)