Hi Pierre and Maria,
Thanks for the suggestions. I tried both of the solutions. Both are able to do what I want.
FYI - Just want to mention there is an extra closing parenthesis. After I removed it, it works fine.
Original:
incident.addNote(json.dumps(playbook.functions.results.rest_response),indent=2))
Modified
incident.addNote(json.dumps(playbook.functions.results.rest_response,indent=2))
------------------------------
Ray Tam
------------------------------
Original Message:
Sent: Thu March 28, 2024 08:46 AM
From: Pierre Dufresne
Subject: How to see the result from a function?
Hi,
On my part, what I usually do is:
import json
incident.addNote(json.dumps(playbook.functions.results.rest_response),indent=2))
The indent parameter will make the output much clearer.
------------------------------
Pierre Dufresne
Original Message:
Sent: Wed March 27, 2024 04:55 PM
From: Ray Tam
Subject: How to see the result from a function?
What is the best way to see the result returned by a function? E.g. a function does an API call and returns a json result.
I tried to output the results to Notes. The result looks like a json output but when I parse it using a json tool, it doesn't like the format.
Below are the two addNote output scripts I tried. I am open to other ideas that can help visualize the result from a function.
Output script 1:
import json
results = playbook.functions.results.rest_response
incident.addNote("ipinfo.\n{}".format(results.get("content", {})))
Output script 2:
import json
results = playbook.functions.results.rest_response
data = json.dumps(results)
incident.addNote(str(results))
Noe: The intend to view the result is to figure out how to pull specific fields and values needed from the json dictionary.
------------------------------
Ray Tam
------------------------------