<?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: Prisma Cloud API: Unable to create a new alert rule with a Microsoft Teams Integration in Prisma Cloud Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546969#M974</link>
    <description>&lt;P&gt;I have solved it, the problem was that the integration itself was not enclosed inside an array, as seen here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;$PrismaNewTeamsAlerRule = @{
    Uri = "$URI" + "alert/rule"
    Method= "POST"
    Headers= @{"x-redlock-auth"= $token;"Accept"= "application/json";"charset"="UTF-8";"content-type"="application/json"}
    Body = @{
            "name"="$AlertRuleName"
            "description"="$AlertRuleDescription"
            "allowAutoRemediate"=$false
            "enabled"=$true
            "scanAll"=$false
            "policies"=$policies
            "target"=@{
                "accountGroups"=$AccountGroupIDs
                "alertRulePolicyFilter"=@{
                    "policy.severity"=$Severity
                    "cloud.type"=$CloudType
                    "policy.complianceStandard"=$ComplianceStandard
                }
            }
            "alertRuleNotificationConfig"=@(@{ #Array added
                 "daysOfWeek"=@(@{
                     "day"=$daysOfWeek
                     "offset"=0
                })
                "enabled"=$true
                "detailedReport"=$false
                "frequency"=$Frequency
                "withCompression"=$false
                "includeRemediation"=$false
                "recipients"=$IntegrationID
                "type"=$IntegrationType
            })
    } | ConvertTo-Json -Depth 4
}&lt;/LI-CODE&gt;
&lt;P&gt;I also had to add the conversion to JSON with Depth 4, as adding the array adds an additional depth grade. I have checked the pan.dev page with the add alert rule request for the API and it appears in a very unclear way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the response and sorry for the inconvenience.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jun 2023 06:50:26 GMT</pubDate>
    <dc:creator>JLlorente</dc:creator>
    <dc:date>2023-06-23T06:50:26Z</dc:date>
    <item>
      <title>Prisma Cloud API: Unable to create a new alert rule with a Microsoft Teams Integration</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546229#M965</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been unable to create an alert rule using the &lt;LI-PRODUCT title="Prisma Cloud" id="Prisma_Cloud"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;CSPM API that contains the "alertRuleNotificationConfig" inside the body in order to link it to a Microsoft Teams Integration, here are the steps that I have followed to do it:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Save the correct base URI in a variable.&lt;/LI&gt;
&lt;LI&gt;Login and obtain the token.&lt;/LI&gt;
&lt;LI&gt;Obtain the AccountGroupID.&lt;/LI&gt;
&lt;LI&gt;Create a new Alert rule. Until this point, without the "alertRuleNotificationConfig", it works and creates a new alert rule.&lt;/LI&gt;
&lt;LI&gt;Tried to add the alert rule part to the Body, keeps responding 400 (Bad Request)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The PowerShell code is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;function New-PrismaCloudTeamsAlertRule{
    param(
        #String with the JWT token
        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [String]
        $Token,

        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [String]
        $AlertRuleName,
        
        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [String]
        $AlertRuleDescription,

        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [array]
        $AccountGroupIDs,

        
        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [array]
        $Severity,

        
        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [array]
        $CloudType,

        
        [Parameter(
        Mandatory=$true,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [array]
        $ComplianceStandard,

        [Parameter(
        Mandatory=$false,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [array]
        $TeamsIntegrationID,

        [Parameter(
        Mandatory=$false,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [ValidateSet("as_it_happens","daily","weekly","monthly")]
        [String]
        $Frequency,
        
        [Parameter(
        Mandatory=$false,
        HelpMessage="Introduce a valid token in String format",
        ValueFromPipeline=$true)]
        [string]
        $daysOfWeek="MO"
)

#Check severity
$ref=@('critical','high','medium','low','informational')
$refregex=[string]::Join('|',$ref)
if($Severity -notmatch $refregex){
    exit
}
$Severity = $Severity.ToUpper()

#Check cloud type
$ref=@('All','AWS','Azure','Alibaba_Cloud','OCI','IBM')
$refregex=[string]::Join('|',$ref)
if($CloudType -notmatch $refregex){
    exit
}
$CloudType = $CloudType.ToLower()



$PrismaNewTeamsAlerRule = @{
    Uri = "$URI" + "alert/rule"
    Method= "POST"
    Headers= @{"x-redlock-auth"= $token;"Accept"= "application/json";"charset"="UTF-8";"content-type"="application/json"}
    Body = @{
            "name"="$AlertRuleName"
            "description"="$AlertRuleDescription"
            "allowAutoRemediate"=$false
            "enabled"=$true
            "scanAll"=$false
            "target"=@{
                "accountGroups"=$AccountGroupIDs
                "alertRulePolicyFilter"=@{
                    "policy.severity"=$Severity
                    "cloud.type"=$CloudType
                    "policy.complianceStandard"=$ComplianceStandard
                }
            }
            "alertRuleNotificationConfig"=@{
                 "daysOfWeek"=@(@{
                     "day"=$daysOfWeek
                     "offset"=[int]0
                })
                "enabled"=$true
                "detailedReport"=$false
                "frequency"=$Frequency
                "withCompression"=$false
                "includeRemediation"=$false
                "recipients"=$TeamsIntegrationID
                "type"='microsoft_teams'
            }
                
    } | ConvertTo-Json -Depth 3
}
$PrismaNewTeamsAlerRule.Body
Invoke-RestMethod @PrismaNewTeamsAlerRule -Verbose
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 09:29:30 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546229#M965</guid>
      <dc:creator>JLlorente</dc:creator>
      <dc:date>2023-06-16T09:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Prisma Cloud API: Unable to create a new alert rule with a Microsoft Teams Integration</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546667#M971</link>
      <description>&lt;P&gt;Bump.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 08:23:39 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546667#M971</guid>
      <dc:creator>JLlorente</dc:creator>
      <dc:date>2023-06-21T08:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Prisma Cloud API: Unable to create a new alert rule with a Microsoft Teams Integration</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546967#M973</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see you are getting 400 Bad request, can you please share which one of the below errors are you getting&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;invalid_param_value / auto_remediation_only_for_config_remediable_policies / missing_required_param / non_notification_state_selected / invalid_notification_state / invalid_resource_list_id / snooze_time_must_be_relative / dismissal_reason_required / has_overlaps_in_resource_list_rules / missing_required_param&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We will need to first add the integration via the API or Prisma Cloud Console and then run the API to add the alert rule with the actual integration name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More details on adding integration here &amp;gt;&amp;gt;&amp;gt;&amp;nbsp;&lt;A href="https://pan.dev/prisma-cloud/api/cspm/create-integration-v-1/" target="_blank"&gt;https://pan.dev/prisma-cloud/api/cspm/create-integration-v-1/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the integration has been added, in this case Microsoft_teams, make sure we are using either of below 3 for&amp;nbsp;&lt;STRONG&gt;recipients&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;For email notifications: List of unique email addresses to notify
For integrations without notification templates: List of integration ids
For integrations with notification templates: List of notification template ids&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and for '&lt;STRONG&gt;type'&lt;/STRONG&gt; use&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;microsoft_teams&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your schema shall have similar to what we see below: additional details here &amp;gt;&amp;gt;&amp;gt;&amp;nbsp;&lt;A href="https://pan.dev/prisma-cloud/api/cspm/add-alert-rule/" target="_blank"&gt;https://pan.dev/prisma-cloud/api/cspm/add-alert-rule/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
"alertRuleNotificationConfig": [
{
"dayOfMonth": 0,
"daysOfWeek": [
{
"day": "SU",
"offset": 0
}
],
"detailedReport": true,
"enabled": true,
"frequency": "as_it_happens",
"frequencyFromRRule": "string",
"hourOfDay": 0,
"id": "string",
"includeRemediation": true,
"lastUpdated": 0,
"last_sent_ts": 0,
"recipients": [
"0346b5dd-5b3c-88d8-a1543-ad2c006fe076" 
],
"rruleSchedule": "string",
"templateId": "string",
"timezone": "string",
"type": "microsoft_teams",
"withCompression": true
}
],
"allowAutoRemediate": true,
"delayNotificationMs": 0,
"description": "string",
"enabled": true,
"lastModifiedBy": "string",
"lastModifiedOn": 0,
"name": "string",
"notifyOnDismissed": true,
"notifyOnOpen": true,
"notifyOnResolved": true,
"notifyOnSnoozed": true,
"policies": [
"string"
],
"policyLabels": [
"string"
],
"policyScanConfigId": "string",
"scanAll": true,
"target": {
"accountGroups": [
"string"
],
"alertRulePolicyFilter": {
"availablePolicyFilters": [
"string"
],
"cloud.type": [
"ALL"
],
"policy.complianceStandard": [
"string"
],
"policy.label": [
"string"
],
"policy.severity": [
"string"
]
},
"excludedAccounts": [
"string"
],
"includedResourceLists": {
"computeAccessGroupIds": [
"string"
]
},
"regions": [
"string"
],
"tags": [
{
"key": "string",
"values": [
"string"
]
}
]
}
}





&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us know if there are any additional questions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 06:43:32 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546967#M973</guid>
      <dc:creator>knaqvi</dc:creator>
      <dc:date>2023-06-23T06:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Prisma Cloud API: Unable to create a new alert rule with a Microsoft Teams Integration</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546969#M974</link>
      <description>&lt;P&gt;I have solved it, the problem was that the integration itself was not enclosed inside an array, as seen here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;$PrismaNewTeamsAlerRule = @{
    Uri = "$URI" + "alert/rule"
    Method= "POST"
    Headers= @{"x-redlock-auth"= $token;"Accept"= "application/json";"charset"="UTF-8";"content-type"="application/json"}
    Body = @{
            "name"="$AlertRuleName"
            "description"="$AlertRuleDescription"
            "allowAutoRemediate"=$false
            "enabled"=$true
            "scanAll"=$false
            "policies"=$policies
            "target"=@{
                "accountGroups"=$AccountGroupIDs
                "alertRulePolicyFilter"=@{
                    "policy.severity"=$Severity
                    "cloud.type"=$CloudType
                    "policy.complianceStandard"=$ComplianceStandard
                }
            }
            "alertRuleNotificationConfig"=@(@{ #Array added
                 "daysOfWeek"=@(@{
                     "day"=$daysOfWeek
                     "offset"=0
                })
                "enabled"=$true
                "detailedReport"=$false
                "frequency"=$Frequency
                "withCompression"=$false
                "includeRemediation"=$false
                "recipients"=$IntegrationID
                "type"=$IntegrationType
            })
    } | ConvertTo-Json -Depth 4
}&lt;/LI-CODE&gt;
&lt;P&gt;I also had to add the conversion to JSON with Depth 4, as adding the array adds an additional depth grade. I have checked the pan.dev page with the add alert rule request for the API and it appears in a very unclear way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the response and sorry for the inconvenience.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 06:50:26 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/prisma-cloud-api-unable-to-create-a-new-alert-rule-with-a/m-p/546969#M974</guid>
      <dc:creator>JLlorente</dc:creator>
      <dc:date>2023-06-23T06:50:26Z</dc:date>
    </item>
  </channel>
</rss>

