Business rule to trigger oauth 2.0 REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2023 12:35 PM
Hi,
Need help to fix my BR.
I have a oauth2.0 REST API integration. I have created application registry, credentials and the REST Message with below JSON body and tested it. It worked fine, getting 200 success response.
Now I need to trigger this REST Message using a Business rule. Below is my code but I am not sure how to pass the response dynamically. Because right now when my BR triggers it give me the response with sample values.
SAMPLE JSON BELOW
{
"entityType": "ASSET",
"update": [
{
"entityId": "0001639",
"fields": {
"item": [
{
"name": "Asset Status",
"value": "CLOSED"
}
{
"name": "Asset Location",
"value": "XYZ"
}
]
}
}
]
}
BUSINESS RULE BELOW:
var request = new sn_ws.RESTMessageV2('Test Integration ', 'PUT method');
request.setStringParameterNoEscape('Asset status', current.u_asset_status);
request.setStringParameterNoEscape('Asset Location', current.u_asset_location);
request.execute();
var response = request.execute();
var requestBody = request.getRequestBody();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(responseBody);
ISSUE : using this BR, the response I am getting is mentioned below, Instead of the dynamic values of asset status and asset location.
Response:
"code":"Success","data":[{"update":{"entityId":"0001639","fields":{"item":[{"name":"Asset Status","value":"CLOSED"},{"name":"Asset Location","value":"XYZ"}]}},"status":{"type":"SUCCESS","statusCode":200}}]}