<?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: AMP4E API - Create new Event Stream using PowerShell in Endpoint Security</title>
    <link>https://community.cisco.com/t5/endpoint-security/amp4e-api-create-new-event-stream-using-powershell/m-p/3928610#M34</link>
    <description>&lt;P&gt;So, just as an update...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without adding the other Group GUIDs to the connection, I am still seeing events from ALL of the groups we currently have in out AMP deployment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which then leads me to presuppose that the initial GUID value in the request was simply a 'place marker' rather than an actual functioning filter or limiter...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* shrug *&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2019 14:18:27 GMT</pubDate>
    <dc:creator>MichaelErana</dc:creator>
    <dc:date>2019-09-23T14:18:27Z</dc:date>
    <item>
      <title>AMP4E API - Create new Event Stream using PowerShell</title>
      <link>https://community.cisco.com/t5/endpoint-security/amp4e-api-create-new-event-stream-using-powershell/m-p/3910916#M19</link>
      <description>&lt;P&gt;First off a nod to&amp;nbsp;&lt;SPAN class="UserName lia-user-name lia-user-rank-Beginner lia-component-message-view-widget-author-username"&gt;&lt;A href="https://community.cisco.com/t5/user/viewprofilepage/user-id/225679" target="_self"&gt;&lt;SPAN class=""&gt;ChiefSec-SF&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;A href="https://community.cisco.com/t5/user/viewprofilepage/user-id/824426" target="_self"&gt;Orlith&lt;/A&gt;&amp;nbsp;for their contributions.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Objective: Use PowerShell to create a new Event Stream.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Define Authentication Credentials&lt;/P&gt;&lt;PRE&gt;$Credentials = GET-CREDENTIAL –Credential (Get-Credential)
$RESTAPIUser = $Credentials.UserName
$RESTAPIPassword = $Credentials.GetNetworkCredential().Password

$apiCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($RESTAPIUser+":"+$RESTAPIPassword))&lt;/PRE&gt;&lt;P&gt;Next set TLS so we don't get annoying errors&lt;/P&gt;&lt;PRE&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12&lt;/PRE&gt;&lt;P&gt;Now start building the headers&lt;/P&gt;&lt;PRE&gt;$headers = @{}
$headers.add("accept","application/json")
$headers.add("Content-Type","application/json")
$headers.add("Authorization", "Basic $apiCreds")&lt;/PRE&gt;&lt;P&gt;Get a list of the current event types for use in the stream construction&lt;/P&gt;&lt;PRE&gt;$url = "https://api.amp.cisco.com/v1/event_types"
$etList = Invoke-RestMethod -Method GET -Headers $headers -Uri $url

$etListSimple = $etList.data.id&lt;/PRE&gt;&lt;P&gt;I know I could have simplified that but I like to be able to Get-Method on the higher level object as I sort stuff out.&lt;/P&gt;&lt;P&gt;$etListSimple are the IDs of all of the event types.&lt;/P&gt;&lt;P&gt;Ideally I would like to also include all of the groups that I currently have defined and I could do that with the following:&lt;/P&gt;&lt;PRE&gt;$url = "https://api.amp.cisco.com/v1/groups"
$ggList = Invoke-RestMethod -Method GET -Headers $headers -Uri $url
$gGUIDs = $ggList.data.guid&lt;/PRE&gt;&lt;P&gt;$gGUIDs would be all of the group GUIDs presently defined.&lt;/P&gt;&lt;P&gt;Now to redefine the headers for the actual event stream creation attempt.&lt;/P&gt;&lt;PRE&gt;$headers = @{}
$headers.add("accept","application/json")
$headers.add("Content-Type","application/json")
$headers.add("Accept-Encoding","gzip, deflate")
$headers.add("content-length","99")
$headers.add("Authorization", "Basic $apiCreds")&lt;/PRE&gt;&lt;P&gt;Next we assemble the post body&lt;/P&gt;&lt;PRE&gt;$guid = "b1143121-0ffc-4c89-98b4-e3151ded376d"

$postData = @{name = "ampTest01"
	event_type = $etListSimple
	group_guid = $guid
	}

$body = $postData | convertto-json -compress&lt;/PRE&gt;&lt;P&gt;Looks legit so far.&lt;/P&gt;&lt;P&gt;Here's where I start to run into trouble. Invoke-RestMethod was unsuccessful in past attempts. Perhaps because of the need to provide "Compress" as a parameter as shown in the &lt;A href="https://api-docs.amp.cisco.com/api_actions/details?api_action=POST+%2Fv1%2Fevent_streams&amp;amp;api_host=api.amp.cisco.com&amp;amp;api_resource=EventStream&amp;amp;api_version=v1" target="_blank" rel="noopener"&gt;cURL example&lt;/A&gt;. Therefore I went with Invoke-WebRequest instead.&lt;/P&gt;&lt;PRE&gt;$esCreateResult = invoke-webrequest -Method Post -uri $url -TransferEncoding "Compress" -Headers $headers -Body $body&lt;/PRE&gt;&lt;P&gt;Un-fortunately this is unsuccessful also. The error is not really helpful so I am hoping someone out there can throw me a bone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;PS C:\WIP&amp;gt; $esCreateResult = invoke-webrequest -Method Post -uri $url -TransferEncoding "Compress" -Headers $headers -Body $body&lt;BR /&gt;invoke-webrequest : Internal Server Error&lt;BR /&gt;The server encountered an internal error or misconfiguration and was unable to complete your request.&lt;BR /&gt;Please contact the server administrator at webmaster@immunet.com to inform them of the time this error occurred, and the actions you performed just before this error.&lt;BR /&gt;More information about this error may be available in the server error log.&lt;BR /&gt;At line:1 char:19&lt;BR /&gt;+ ... ateResult = invoke-webrequest -Method Post -uri $url -TransferEncodin ...&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException&lt;BR /&gt;+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand&lt;/LI-SPOILER&gt;&lt;P&gt;The final objective is to include ALL groups in the stream and not just the one as I am showing in this example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking forward to your comments and suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 05:10:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/endpoint-security/amp4e-api-create-new-event-stream-using-powershell/m-p/3910916#M19</guid>
      <dc:creator>MichaelErana</dc:creator>
      <dc:date>2020-02-21T05:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: AMP4E API - Create new Event Stream using PowerShell</title>
      <link>https://community.cisco.com/t5/endpoint-security/amp4e-api-create-new-event-stream-using-powershell/m-p/3928610#M34</link>
      <description>&lt;P&gt;So, just as an update...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without adding the other Group GUIDs to the connection, I am still seeing events from ALL of the groups we currently have in out AMP deployment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which then leads me to presuppose that the initial GUID value in the request was simply a 'place marker' rather than an actual functioning filter or limiter...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* shrug *&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 14:18:27 GMT</pubDate>
      <guid>https://community.cisco.com/t5/endpoint-security/amp4e-api-create-new-event-stream-using-powershell/m-p/3928610#M34</guid>
      <dc:creator>MichaelErana</dc:creator>
      <dc:date>2019-09-23T14:18:27Z</dc:date>
    </item>
  </channel>
</rss>

