The CreatorCon Call for Content is officially open! Get started here.

How to check the api call successful or failed from 3rd party ?

jaiho_rai
Kilo Sage

Hi Team ,

 

How do I check if the API call from a 3rd party is successful or failed ?

How should I update the worknote only once? The next call should not update the worknote in inc ?

1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@jaiho_rai 

you can use below code to check API call fail/pass

 

// Make API call to third-party system
var response = thirdPartyApiCall();

// Check if the API call was successful
if (response && response.getStatusCode() === 200) {
    // API call was successful
    var responseBody = response.getBody(); // You can inspect the response body for further details
    gs.info("API call successful. Response: " + responseBody);

    // Update incident or take further actions based on the response
} else {
    // API call failed
    gs.error("API call failed. Status code: " + response.getStatusCode());

    // Handle error scenario or log error details
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

View solution in original post

9 REPLIES 9

Hi @jaiho_rai 

I am not expert, but in this case  2 API, one of create and 2nd for update. in first update Work notes and in 2nd dont add this.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Maddysunil
Kilo Sage

@jaiho_rai 

you can use below code to check API call fail/pass

 

// Make API call to third-party system
var response = thirdPartyApiCall();

// Check if the API call was successful
if (response && response.getStatusCode() === 200) {
    // API call was successful
    var responseBody = response.getBody(); // You can inspect the response body for further details
    gs.info("API call successful. Response: " + responseBody);

    // Update incident or take further actions based on the response
} else {
    // API call failed
    gs.error("API call failed. Status code: " + response.getStatusCode());

    // Handle error scenario or log error details
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

but it should be only the first time, not every time I need to go , Let I open an incident that API calls for first time it will update the work note whether it is successful or failed, and then there is no need to update.

 

Script APIs as well they are utilizing import set.

Amit Verma
Kilo Patron
Kilo Patron

Hi @jaiho_rai 

 

So you mean to say that an Incident update can happen either via Scripted REST API call or via Import Set, if the incident is successfully updated with a worknote, another API call to update the worknote should be dropped off. If API call fails, then you want to send the email ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Deeksh
Tera Contributor

Hi @jaiho_rai ,

To detect whether a third-party API call is successful and ensure the Incident worknote is updated only once, follow this structured approach:

  1. Create a Business Rule (BR) on the sys_outbound_http_log table.
  2. Apply the following filter conditions in the BR:
    Deeksh_1-1748522381099.png

     

Encoded Query: app_scope=global^

response_status=200^ORresponse_status=201^

method=GET^ORmethod=POST^

url=^path=

  • Use url for general endpoint matches (e.g., /maps/api/distancematrix/xml)
  • Use path for exact URL matching (including parameters)
  • Select your application scope as per your requirement — for example, global.
  1. To ensure that the worknote is updated only once, implement one of the following control mechanisms:

Option A: Worknote Tag Check (Simple)

  • Use GlideRecord to retrieve the related Incident (INC) record.
  • Check if the worknote already contains a unique marker such as:

"Note: Updated by [Business Rule Name]"

  • If it exists, abort the update. If not, append the note and include the marker.

Option B: Hidden Flag Field (Recommended for cleaner tracking)

  • Add a custom boolean field to the incident table (e.g., u_api_note_updated).
    • Set it as not displayed on the form, so it's only available in the backend.
  • Update your Business Rule's script condition or filter to run only if this flag is false.
  • When the BR successfully updates the worknote, set u_api_note_updated = true.
  • This ensures the rule will not execute again for the same Incident.
    *************************************************************************************************************
    If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

    Regards
    Deek**bleep**h A C
    ServiceNow Techno-Developer
    LinkedIn: https://www.linkedin.com/in/deeksh-servicenow/
    ****************************************************************************************************************