I tried again and figured out I was missing the double quote. The API call is now working fine even if there is no match. Thanks a lot for the solution.
Original Message:
Sent: Tue August 13, 2024 12:00 PM
From: Raymond Tam
Subject: CALL REST API timeout issue when it doesn't return status code
Thanks for the suggestion; since I am using the script, I added that in the allowed status in the code but got this error. Anyone has any ideas if I am doing it right?
See my REST API CAll script below.

import json
results = playbook.functions.results.rest_token
content = results.content
token = content.text
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': token
}
inputs.rest_api_method = 'GET'
inputs.rest_api_headers = json.dumps(headers)
inputs.rest_api_url = 'https://forescout.mycompany.com/api/hosts/ip/{}'.format(artifact.value)
inputs.rest_api_verify = False
inputs.rest_api_timeout = 60
inputs.rest_api_allowed_status_codes = 404
------------------------------
Raymond Tam
Original Message:
Sent: Mon August 12, 2024 11:51 PM
From: Allen Lee
Subject: CALL REST API timeout issue when it doesn't return status code
Hi Raymond,
Can you try to put the rest_api_allowed_status_codes in 404?

When I do this, it will succeed in outputting the incident note.

------------------------------
Allen Lee
Original Message:
Sent: Thu August 08, 2024 09:15 PM
From: Raymond Tam
Subject: CALL REST API timeout issue when it doesn't return status code
Thanks for the suggestion. I just tried that but got the same error.
I do understand your point. In most cases, I was able to do a simple output script to show the AP return details either there is a match or not.
In this situation, if API search is not found, the playbook can't run and simple return an error.
I even tried this output script below to get the API result but still getting an error when there is no match.
results = playbook.functions.results.rest_result
incident.addNote(f"{results}")
------------------------------
Raymond Tam
Original Message:
Sent: Thu August 08, 2024 08:32 PM
From: Allen Lee
Subject: CALL REST API timeout issue when it doesn't return status code
Hi Raymond,
The rest api result should be like:
[rest_api] Result: {'version': 2.0, 'success': True, 'reason': None, 'content': {'ok': True, 'url': 'https://github.com/', 'status_code': 200, 'reason': 'OK',.........
So, the output script you can adjust it as follows,
results = playbook.functions.results.rest_result
if results.content.status_code != 200:
incident.addNote("404 Error: Host Not found")
else:
incident.addNote(str(results))
I hope this is of assistance.
------------------------------
Allen Lee
Original Message:
Sent: Thu August 08, 2024 05:54 PM
From: Raymond Tam
Subject: CALL REST API timeout issue when it doesn't return status code
I am using the CALL REST API module with the Forescout.
When making the API call to Forescout, if the IP finds a match, it returns the result fine.
In the case there is no match, the playbook timeout with error.
https://forescout.mycompay/api/hosts/ip/1.1.1.1'

I tried the output script below to validate the status code but still getting the timeout issue when there is no match. what condition can I use to get pass this error.
import json
import re
results = playbook.functions.results.rest_result
#
if result.status_code != 200
incident.addNote("404 Error: Host Not found")
else:
incident.addNote(str(results))
------------------------------
Raymond Tam
------------------------------