Hello everybody,
We have a requirement to call an API from ServiceDesk Plus to a 3rd party application in order to update the request data in the 3rd party application. To initiate the API call, we generate a dynamic Bearer token, which is not static. We then use this token to make the API call. If the token were static, we could use a webhook to fulfill the requirement, but in this case, it's dynamic.
We've written the following code to achieve this requirement, but it is not working as expected. Please review and correct the script. Your assistance in rectifying this would be greatly appreciated in meeting the requirement.
//Authentication authUrl = ""; username =""; password =""; _data = Map(); _data.put("username","******"); _data.put("password","*******"); _payload = {"username":"*******", "password":"*******"}; headers = map(); headers.put("Content-Type", "application/json"); _response= postUrl("http://....................../gastat/authentication/auth/authenticate"); if (_response.get("responseCode") == 200) { info _response.get("responseBody"); // Define the URL and payload url = "http://......................../gastat/admin/manageEngine/updateRPId"; data = Map(); data.put("rpId", 18272); data.put("surveyId", 12); // Convert payload to JSON payload = {"rpId":"18272", "surveyId":"12"}; // Define headers headers = map(); headers.put("Authorization", "Bearer "); headers.put("Content-Type", "application/json"); // Make the HTTP request response = postUrl(url, payload, headers); // Check response status if (response.get("responseCode") == 200) { // Successful API call info "API call successful"; info response.get("responseBody"); // Log the response data } else { // Failed API call info "API call failed"; info response.get("responseBody"); // Log the error message } } else{ }