<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting playbook output data from phantom.playbook API call in Splunk SOAR</title>
    <link>https://community.splunk.com/t5/Splunk-SOAR/Getting-playbook-output-data-from-phantom-playbook-API-call/m-p/760794#M1884</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/253030"&gt;@nongingerale&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I don't have much experience but what I can see is:&lt;/P&gt;&lt;P&gt;phantom.collect2 with a playbook_output datapath works for static visual playbook blocks, not dynamic&lt;BR /&gt;calls from custom code in a loop. With a dynamic name, the datapath can't be resolved the way SOAR's data engine expects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe you can try to handle it in python code, something like this:&lt;/P&gt;&lt;P&gt;(code not tested)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def my_callback(action=None, success=None, container=None, results=None, handle=None, **kwargs):                     
      phantom.debug("my_callback() called")
                                                                                                                       
      for result in results:                                                                                           
          run_id = result.get('playbook_run_id')
          if not run_id:                                                                                               
              continue                                           
                                               
          # Hit SOAR's internal REST API — no auth token needed when called from within a playbook                     
          response = phantom.requests.get(
              f'/rest/playbook_run/{run_id}',                                                                          
              verify=False                                       
          )                                                                                                            
                                                                 
          if response.status_code != 200:      
              phantom.error(f"Failed to get playbook run {run_id}: {response.status_code}")
              continue                                                                                                 
  
          run_data = response.json()                                                                                   
          raw_outputs = run_data.get('outputs')  # list of JSON-encoded strings
                                                                                                                       
          if not raw_outputs:
              phantom.debug(f"No outputs for run {run_id} — is the subplaybook an input playbook with defined outputs?")                                                                                                           
              continue                         
                                                                                                                       
          for raw in raw_outputs:                                
              output = json.loads(raw)         
              search_results = output.get('search_results_data')  # your output name                                   
              phantom.debug(f"Got search_results_data: {search_results}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;References:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/Phantom/4.10.7/PlaybookAPI/SessionAPI" target="_blank"&gt;https://docs.splunk.com/Documentation/Phantom/4.10.7/PlaybookAPI/SessionAPI&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://help.splunk.com/en/splunk-soar/soar-cloud/rest-api-reference/run-playbook-endpoints/rest-run-playbook" target="_blank"&gt;https://help.splunk.com/en/splunk-soar/soar-cloud/rest-api-reference/run-playbook-endpoints/rest-run-playbook&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps!!!&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Fri, 08 May 2026 06:30:20 GMT</pubDate>
    <dc:creator>VatsalJagani</dc:creator>
    <dc:date>2026-05-08T06:30:20Z</dc:date>
    <item>
      <title>Getting playbook output data from phantom.playbook API call</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Getting-playbook-output-data-from-phantom-playbook-API-call/m-p/759894#M1874</link>
      <description>&lt;P&gt;I currently have a playbook that runs 3 actions within it (creating a splunk search, sharing the job, and expanding ttl, all while using the loop-if-failure feature) and returns outputs (summary, status, and the search results). I'm trying to do a for-loop where it calls that playbook with different params using phantom.playbook() though I am having trouble finding the actual playbook output in the callback function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;for loop:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;inputs = {&amp;lt;changing params&amp;gt;}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;new_name = "&amp;lt;changing string&amp;gt;"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;phantom.playbook("my_playbook", container=container, name=new_name, input=inputs, callback=my_callback)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;where in my_callback:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I try phantom.collect2(container=container, datapath=["new_name:playbook_output:search_results_data"], action_results=results)&lt;/P&gt;&lt;P&gt;which doesnt work. I tried printing out general "results" which gives me info such as:&lt;BR /&gt;name&lt;BR /&gt;playbook&lt;BR /&gt;playbook_run_id&lt;BR /&gt;result (which contains a dictionary for info on each of the 3 actions)&lt;/P&gt;&lt;P&gt;but this doesnt include the output data of the playbook itself (or the run_query splunk search results).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I did see a past post that didnt get an answer (or at least not the answer that fits my scenario:&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-SOAR/How-to-get-output-data-when-calling-a-playbook-through-the-API/m-p/698278" target="_blank"&gt;https://community.splunk.com/t5/Splunk-SOAR/How-to-get-output-data-when-calling-a-playbook-through-the-API/m-p/698278&lt;/A&gt;). My use case needs to use the subplaybook and not the actions directly due to configuration reasons (mainly the asset field needs to be configurable rather than hard-set via the Splunk App runquery action block).&lt;BR /&gt;&lt;BR /&gt;any help or direction would be super appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2026 18:12:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Getting-playbook-output-data-from-phantom-playbook-API-call/m-p/759894#M1874</guid>
      <dc:creator>nongingerale</dc:creator>
      <dc:date>2026-04-02T18:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting playbook output data from phantom.playbook API call</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Getting-playbook-output-data-from-phantom-playbook-API-call/m-p/760794#M1884</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/253030"&gt;@nongingerale&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I don't have much experience but what I can see is:&lt;/P&gt;&lt;P&gt;phantom.collect2 with a playbook_output datapath works for static visual playbook blocks, not dynamic&lt;BR /&gt;calls from custom code in a loop. With a dynamic name, the datapath can't be resolved the way SOAR's data engine expects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe you can try to handle it in python code, something like this:&lt;/P&gt;&lt;P&gt;(code not tested)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def my_callback(action=None, success=None, container=None, results=None, handle=None, **kwargs):                     
      phantom.debug("my_callback() called")
                                                                                                                       
      for result in results:                                                                                           
          run_id = result.get('playbook_run_id')
          if not run_id:                                                                                               
              continue                                           
                                               
          # Hit SOAR's internal REST API — no auth token needed when called from within a playbook                     
          response = phantom.requests.get(
              f'/rest/playbook_run/{run_id}',                                                                          
              verify=False                                       
          )                                                                                                            
                                                                 
          if response.status_code != 200:      
              phantom.error(f"Failed to get playbook run {run_id}: {response.status_code}")
              continue                                                                                                 
  
          run_data = response.json()                                                                                   
          raw_outputs = run_data.get('outputs')  # list of JSON-encoded strings
                                                                                                                       
          if not raw_outputs:
              phantom.debug(f"No outputs for run {run_id} — is the subplaybook an input playbook with defined outputs?")                                                                                                           
              continue                         
                                                                                                                       
          for raw in raw_outputs:                                
              output = json.loads(raw)         
              search_results = output.get('search_results_data')  # your output name                                   
              phantom.debug(f"Got search_results_data: {search_results}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;References:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://docs.splunk.com/Documentation/Phantom/4.10.7/PlaybookAPI/SessionAPI" target="_blank"&gt;https://docs.splunk.com/Documentation/Phantom/4.10.7/PlaybookAPI/SessionAPI&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://help.splunk.com/en/splunk-soar/soar-cloud/rest-api-reference/run-playbook-endpoints/rest-run-playbook" target="_blank"&gt;https://help.splunk.com/en/splunk-soar/soar-cloud/rest-api-reference/run-playbook-endpoints/rest-run-playbook&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps!!!&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 08 May 2026 06:30:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Getting-playbook-output-data-from-phantom-playbook-API-call/m-p/760794#M1884</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2026-05-08T06:30:20Z</dc:date>
    </item>
  </channel>
</rss>

