Brevo.psm1
#Region './Public/Account and Settings/Accounts/Get-Account.ps1' -1 function Get-Account { <# .SYNOPSIS Get your account information, plan and credits details .DESCRIPTION The `Get-Account` function sends a GET request to the Brevo API to retrieve account details. It uses the `Invoke-BrevoCall` function to perform the API call. .PARAMETERS This function does not take any parameters. .OUTPUTS Returns the account information as an object. .EXAMPLE PS> Get-Account Retrieves the account details from the Brevo API and displays them. #> [CmdletBinding()] param () $params = @{ "URI" = "/account" "Method" = "GET" } $Account = Invoke-BrevoCall @params return $Account } #EndRegion './Public/Account and Settings/Accounts/Get-Account.ps1' 31 #Region './Public/Account and Settings/Domains/Confirm-Domain.ps1' -1 <# .SYNOPSIS Confirms the authentication status of a specified mail domain. .DESCRIPTION The Confirm-Domain function sends a GET request to check the authentication status of a specified mail domain using the Brevo API. It constructs the API endpoint dynamically based on the provided domain name. .PARAMETER name The name of the mail domain to confirm. This parameter is mandatory. .EXAMPLE PS> Confirm-Domain -name "example.com" Returns the authentication status of the domain "example.com". .RETURNS Object The response object containing the domain authentication details. #> function Confirm-Domain { [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Mail domain name")] [string] $name ) $params = @{ "URI" = "/senders/domains/$([uri]::EscapeDataString($name))/authenticate" "Method" = "GET" } $Domain = Invoke-BrevoCall @params return $Domain } #EndRegion './Public/Account and Settings/Domains/Confirm-Domain.ps1' 35 #Region './Public/Account and Settings/Domains/Get-Domain.ps1' -1 function Get-Domain { <# .SYNOPSIS Get the list of all your domains .DESCRIPTION The Get-Domain function sends a GET request to the Brevo API to retrieve information about the configured sender domains. It uses the Invoke-BrevoCall function to perform the API call. .PARAMETERS This function does not take any parameters. .OUTPUTS Returns the response from the Brevo API containing the list of sender domains. .EXAMPLE PS> Get-Domain Retrieves the list of sender domains from the Brevo API. #> [CmdletBinding()] param () $params = @{ "URI" = "/senders/domains" "Method" = "GET" } $Domain = Invoke-BrevoCall @params return $Domain } #EndRegion './Public/Account and Settings/Domains/Get-Domain.ps1' 33 #Region './Public/Account and Settings/Domains/New-Domain.ps1' -1 function New-Domain { <# .SYNOPSIS Creates a new mail domain. .DESCRIPTION The New-Domain function is used to create a new mail domain by sending a POST request to the "/senders/domains" endpoint. It requires the domain name as input and returns the created domain information. .PARAMETER name Specifies the name of the mail domain to be created. This parameter is mandatory. .EXAMPLE PS> New-Domain -name "example.com" Creates a new mail domain with the name "example.com". #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Mail domain name")] [string] $name ) $params = @{ "URI" = "/senders/domains" "Method" = "POST" } $body = @{ name = $name } $Domain = Invoke-BrevoCall @params return $Domain } #EndRegion './Public/Account and Settings/Domains/New-Domain.ps1' 35 #Region './Public/Account and Settings/Domains/Remove-Domain.ps1' -1 function Remove-Domain { <# .SYNOPSIS Removes a specified mail domain. .DESCRIPTION The Remove-Domain function deletes a mail domain by making an API call to the specified endpoint. The function uses the domain name provided as input to construct the API request. .PARAMETER name The name of the mail domain to be removed. This parameter is mandatory. .EXAMPLE Remove-Domain -name "example.com" This example removes the mail domain "example.com". #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true, HelpMessage = "Mail domain name")] [string] $name ) $params = @{ "URI" = "/senders/domains/$([uri]::EscapeDataString($name))" "Method" = "DELETE" } $body = @{ name = $name } if ($PSCmdlet.ShouldProcess("$name", "Remove-Domain")) { $Domain = Invoke-BrevoCall @params return $Domain } } #EndRegion './Public/Account and Settings/Domains/Remove-Domain.ps1' 37 #Region './Public/Account and Settings/Domains/Test-Domain.ps1' -1 function Test-Domain { <# .SYNOPSIS Authenticate a domain .DESCRIPTION The `Test-Domain` function sends a GET request to check the existence or retrieve details of a specified mail domain using the Brevo API. The domain name is passed as a parameter, and the function returns the domain information. .PARAMETER name Specifies the mail domain name to be tested or queried. This parameter is mandatory. .EXAMPLE Test-Domain -name "example.com" This command authenticates the domain "example.com". .RETURNS Returns $true if the domain authenticates successfully #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Mail domain name")] [string] $name ) $params = @{ "URI" = "/senders/domains/$([uri]::EscapeDataString($name))" "Method" = "GET" } $Domain = Invoke-BrevoCall @params return $Domain } #EndRegion './Public/Account and Settings/Domains/Test-Domain.ps1' 35 #Region './Public/Account and Settings/Senders/Get-Sender.ps1' -1 function Get-Sender { <# .SYNOPSIS Get the list of all your senders .DESCRIPTION The Get-Sender function sends a GET request to the Brevo API to retrieve information about the configured sender domains. It uses the Invoke-BrevoCall function to perform the API call. .PARAMETERS This function does not take any parameters. .OUTPUTS Returns the response from the Brevo API containing the list of sender domains. .EXAMPLE PS> Get-Sender Retrieves the list of sender domains from the Brevo API. #> [CmdletBinding()] param () $params = @{ "URI" = "/senders" "Method" = "GET" "returnobject" = "senders" } $Sender = Invoke-BrevoCall @params return $Sender } #EndRegion './Public/Account and Settings/Senders/Get-Sender.ps1' 33 #Region './Public/Account and Settings/Senders/New-Sender.ps1' -1 function New-Sender { <# .SYNOPSIS Create a new sender domain in Brevo. .DESCRIPTION The New-Sender function sends a POST request to the Brevo API to create a new sender domain. It uses the Invoke-BrevoCall function to perform the API call. .PARAMETERS -Email: The email address of the sender. -Name: The name of the sender. -ReplyTo: The reply-to email address for the sender. -ReturnPath: The return path email address for the sender. -Domain: The domain of the sender. -UpdateEnabled: Set this field to update the existing sender in the same request. Default is false. .OUTPUTS Returns the response from the Brevo API containing information about the created sender domain. .EXAMPLE PS> New-Sender -Email " #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The email address of the sender")] [string]$Email, [Parameter(Mandatory = $true, HelpMessage = "The name of the sender")] [string]$Name, [Parameter(Mandatory = $false, HelpMessage = "array of objects. Mandatory in case of dedicated IP. IPs to associate to the sender. For example: @( @{ip = ""x.x.x.x""; domain = ""mydomain.com"";weight = 1})")] $ips ) $params = @{ "URI" = "/senders" "Method" = "POST" } $params["Body"] = @{ "email" = $Email "name" = $Name } if ($ips) { if ($ips -is [array]) { $params["Body"]["ips"] = $ips } else { throw "The 'ips' parameter must be an array of objects." } } $Sender = Invoke-BrevoCall @params return $Sender } #EndRegion './Public/Account and Settings/Senders/New-Sender.ps1' 54 #Region './Public/Account and Settings/Senders/Remove-Sender.ps1' -1 function Remove-Sender { <# .SYNOPSIS Delete a sender domain in Brevo. .DESCRIPTION The Remove-Sender function sends a DELETE request to the Brevo API to remove a sender domain. It uses the Invoke-BrevoCall function to perform the API call. .PARAMETER SenderId The ID of the sender domain to be removed. .EXAMPLE PS> Remove-Sender -SenderId 1234567890 Removes the sender domain with ID 1234567890 from Brevo. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The ID of the sender domain to be removed")] [string]$SenderId ) $params = @{ "URI" = "/senders/$SenderId" "Method" = "DELETE" } $Sender = Invoke-BrevoCall @params return $Sender } #EndRegion './Public/Account and Settings/Senders/Remove-Sender.ps1' 32 #Region './Public/Account and Settings/User/Get-User.ps1' -1 function Get-User { <# .SYNOPSIS Retrieves the user information from the Brevo API. .DESCRIPTION The Get-User function sends a GET request to the Brevo API to retrieve information about invited users in the organization. .PARAMS None .OUTPUTS Returns the user information retrieved from the Brevo API. .EXAMPLE PS> Get-User This example retrieves the user information from the Brevo API. #> $method = "GET" $uri = "/user" $params = @{ "URI" = "/organization/invited/users" "Method" = "GET" "returnobject" = "users" } $user = Invoke-BrevoCall @params return $user } #EndRegion './Public/Account and Settings/User/Get-User.ps1' 30 #Region './Public/Account and Settings/User/Get-UserActivitylog.ps1' -1 function Get-UserActivitylog { <# .SYNOPSIS Get user activity logs. (requires Enterprise plan) .DESCRIPTION The Get-UserActivitylog function retrieves activity logs for users in the account. You can filter the logs by date range, email address, and pagination parameters such as limit and offset. The maximum time period that can be selected is one month, and logs from the past 12 months can be retrieved. .PARAMETER startDate Optional. The start date in UTC date (YYYY-MM-DD) format to filter the activity logs. Mandatory if the endDate parameter is used. .PARAMETER endDate Optional. The end date in UTC date (YYYY-MM-DD) format to filter the activity logs. Mandatory if the startDate parameter is used. .PARAMETER email Optional. The email address of the user to filter their activity logs. .PARAMETER limit Optional. The maximum number of records to retrieve. Defaults to 10. Acceptable values range from 1 to 100. .PARAMETER offset Optional. The number of records to skip before starting to retrieve records. Defaults to 0. .EXAMPLE Get-UserActivitylog -startDate "2023-01-01" -endDate "2023-01-31" -email "user@example.com" -limit 20 -offset 0 This example retrieves the activity logs for the user with the email "user@example.com" for the date range from January 1, 2023, to January 31, 2023, with a maximum of 20 records starting from the first record. .EXAMPLE Get-UserActivitylog -limit 50 This example retrieves up to 50 activity logs without any specific filters. #> [CmdletBinding()] param ( [Parameter(Mandatory = $false, HelpMessage = "Mandatory if endDate is used. Enter start date in UTC date (YYYY-MM-DD) format to filter the activity in your account. Maximum time period that can be selected is one month. Additionally, you can retrieve activity logs from the past 12 months from the date of your search.")] [string]$startDate, [Parameter(Mandatory = $false, HelpMessage = "Mandatory if startDate is used. Enter end date in UTC date (YYYY-MM-DD) format to filter the activity in your account. Maximum time period that can be selected is one month.")] [string]$endDate, [Parameter(Mandatory = $false, HelpMessage = "Enter the user's email address to filter their activity in the account.")] [string]$email, [Parameter(Mandatory = $false, HelpMessage = "1 to 100 Defaults to 10")] [int] $limit, [Parameter(Mandatory = $false, HelpMessage = "Defaults to 0")] [int] $offset = 0 ) $params = @{ "URI" = "/organization/activities" "Method" = "GET" } if ($startDate) { $params["URI"] = $params["URI"] + "?startDate=$startDate" if ($endDate) { $params["URI"] = $params["URI"] + "&endDate=$endDate" } } if ($email) { if ($params["URI"] -like "*?*") { # URI enthält bereits ein ? $params["URI"] = $params["URI"] + "&email=$([uri]::EscapeDataString($email))" } else { # URI enthält noch kein ? $params["URI"] = $params["URI"] + "?email=$([uri]::EscapeDataString($email))" } } if ($limit) { if ($params["URI"] -like "*?*") { # URI enthält bereits ein ? $params["URI"] = $params["URI"] + "&limit=$limit" } else { # URI enthält noch kein ? $params["URI"] = $params["URI"] + "?limit=$limit" } } if ($offset) { if ($params["URI"] -like "*?*") { # URI enthält bereits ein ? $params["URI"] = $params["URI"] + "&offset=$offset" } else { # URI enthält noch kein ? $params["URI"] = $params["URI"] + "?offset=$offset" } } $Account = Invoke-BrevoCall @params return $Account } #EndRegion './Public/Account and Settings/User/Get-UserActivitylog.ps1' 102 #Region './Public/Account and Settings/User/Get-UserPermission.ps1' -1 function Get-UserPermission { <# .SYNOPSIS Retrieves the permissions of a user based on their email. .DESCRIPTION The Get-UserPermission function sends a GET request to retrieve the permissions of a user identified by their email address. It uses the Invoke-BrevoCall function to make the API call and returns the user's permissions. .PARAMETER email The email address of the invited user whose permissions are to be retrieved. This parameter is mandatory. .EXAMPLE PS> Get-UserPermission -email "user@example.com" This command retrieves the permissions for the user with the email "user@example.com". .OUTPUTS Returns the permissions of the specified user. #> [CmdletBinding()] param( [Parameter(Mandatory = $true, HelpMessage = "Email of the invited user.")] [string]$email ) $method = "GET" $uri = "/organization/user/$email/permissions" $params = @{ "URI" = $uri "Method" = $method "returnobject" = "privileges" } $userPermission = Invoke-BrevoCall @params return $userPermission } #EndRegion './Public/Account and Settings/User/Get-UserPermission.ps1' 35 #Region './Public/Account and Settings/User/Send-UserInvitation.ps1' -1 # function Send-UserInvitation { # [CmdletBinding()] # param( # [Parameter(Mandatory = $true, HelpMessage = "Email address for the organization")] # [string]$email, # [Parameter(Mandatory = $true, HelpMessage = "All access to the features")] # [bool]$all_features_access # # [Parameter(Mandatory = $true, HelpMessage = "Privileges for the user. See https://developers.brevo.com/reference/inviteuser for reference")] # # [ValidateSet( # # "email_campaigns_create_edit_delete", # # "email_campaigns_send_schedule_suspend", # # "sms_campaigns_create_edit_delete", # # "sms_campaigns_send_schedule_suspend", # # "contacts_view", # # "contacts_create_edit_delete", # # "contacts_import", # # "contacts_export", # # "contacts_list_and_attributes", # # "contacts_forms", # # "templates_create_edit_delete", # # "templates_activate_deactivate", # # "workflows_create_edit_delete", # # "workflows_activate_deactivate_pause", # # "workflows_settings", # # "facebook_ads_create_edit_delete", # # "facebook_ads_schedule_pause", # # "landing_pages_all", # # "transactional_emails_settings", # # "transactional_emails_logs", # # "smtp_api_smtp", # # "smtp_api_api_keys", # # "smtp_api_authorized_ips", # # "user_management_all", # # "sales_platform_create_edit_deals", # # "sales_platform_delete_deals", # # "sales_platform_manage_others_deals_tasks", # # "sales_platform_reports", # # "sales_platform_settings", # # "phone_all", # # "conversations_access", # # "conversations_assign", # # "conversations_configure", # # "senders_domains_dedicated_ips_senders_management", # # "senders_domains_dedicated_ips_domains_management", # # "senders_domains_dedicated_ips_dedicated_ips_management", # # "push_notifications_view", # # "push_notifications_create_edit_delete", # # "push_notifications_send", # # "push_notifications_settings", # # "companies_manage_owned_companies", # # "companies_manage_other_companies", # # "companies_settings" # # )] # # [string[]]$privileges # #TODO # ) # $body = @{ # "email" = $email # "all_features_access" = $all_features_access # "privileges" = $privileges # } # $uri = "https://api.sendinblue.com/v3/users/$userId/invite" # $Params = @{ # "URI" = $uri # "Method" = "POST" # "Body" = $body # } # $userInvitation = Invoke-BrevoCall @Params # return $userInvitation # } #EndRegion './Public/Account and Settings/User/Send-UserInvitation.ps1' 74 #Region './Public/Connect-Brevo.ps1' -1 <# .SYNOPSIS Connects to the Brevo API using the provided API key and URI. .DESCRIPTION The `Connect-Brevo` function authenticates to the Brevo API using the provided API key and optional API URI. It sets the API URI and API key as script-scoped variables and attempts to connect to the Brevo API. .EXAMPLE Connect-Brevo -APIkey (Get-Credential) Connects to the Brevo API using the provided API key and the default API URI. .INPUTS The function does not accept pipeline input. .OUTPUTS Returns $null if the connection fails, or the account information if the connection is successful. If the -NoWelcome switch is used, it returns $true if the connection is successful, otherwise $null. #> function Connect-Brevo { [CmdletBinding()] [OutputType([object])] param ( [Parameter(Mandatory = $true, HelpMessage = "The API key to use for authentication.")] [pscredential]$APIkey, [Parameter(Mandatory = $false, HelpMessage = "The complete URI of the Brevo API. e.g. https://api.brevo.com/v3/")] [Alias("uri", "apiurl")] [string]$APIuri = "https://api.brevo.com/v3", [Parameter(Mandatory = $false, HelpMessage = "Suppresses the welcome message.")] [switch]$NoWelcome ) $script:APIuri = $APIuri $script:APIkey = $APIkey Write-Debug "$($MyInvocation.MyCommand):API URI: $script:APIuri" $params = @{ "URI" = "$script:APIuri/account" "Method" = "GET" } $Account = Invoke-BrevoCall @params if ($Account) { Write-Host -ForegroundColor Green "Connected to Brevo API" if ($NoWelcome) { return $true } else { return $Account } } else { Write-Host -ForegroundColor Red "Failed to connect to Brevo API" return $null } } #EndRegion './Public/Connect-Brevo.ps1' 59 #Region './Public/Contact Management/Attribute/Get-ContactAttribute.ps1' -1 function Get-ContactAttribute { <# .SYNOPSIS Retrieves contact attributes from the Brevo API. .DESCRIPTION The Get-ContactAttribute function retrieves contact attributes from the Brevo API. It allows filtering by attribute name(s) if specified. The function uses the Invoke-BrevoCall helper function to make the API call. .PARAMETER Name The name of the contact attribute(s) to filter by. This parameter is case-insensitive and can accept a single string or an array of strings. If not specified, all attributes are returned. .EXAMPLE # Retrieve all contact attributes Get-ContactAttribute .EXAMPLE # Retrieve a specific contact attribute by name Get-ContactAttribute -Name "FirstName" .EXAMPLE # Retrieve multiple contact attributes by names Get-ContactAttribute -Name @("FirstName", "LastName") # or Get-ContactAttribute -Name "FirstName", "LastName" .NOTES - This function requires the Invoke-BrevoCall helper function to be defined and accessible. - The "returnobject" parameter in the API call is set to "attributes" to specify the desired data to be returned. #> [CmdletBinding()] param ( [Parameter(Mandatory = $false, HelpMessage = "The name of the contact attribute(s) (case-insensitive)")] [string[]]$Name ) $method = "GET" $uri = "/contacts/attributes" $Params = @{ "URI" = $uri "Method" = $method "returnobject" = "attributes" } $attribute = Invoke-BrevoCall @Params if ((-not [string]::IsNullOrEmpty($name)) -and ($Name -is [String])) { $attribute = $attribute | Where-Object { $_.name -ieq $Name } } if ($Name -is [Array]) { $attribute = $attribute | Where-Object { $Name -contains $_.name } } return $attribute } #EndRegion './Public/Contact Management/Attribute/Get-ContactAttribute.ps1' 57 #Region './Public/Contact Management/Attribute/New-ContactAttribute.ps1' -1 function New-ContactAttribute { <# .SYNOPSIS Creates a new contact attribute in Brevo. .DESCRIPTION The New-ContactAttribute function creates a new contact attribute in Brevo with the specified category, name, and other optional parameters. .PARAMETER attributeCategory Specifies the category of the attribute. Valid values are "normal", "transactional", "category", "calculated", and "global". This parameter is mandatory. .PARAMETER attributeName Specifies the name of the attribute. This parameter is mandatory. .PARAMETER value Specifies the value of the attribute. Use only if the attribute's category is 'calculated' or 'global'. This parameter is optional. .PARAMETER isRecurring Specifies whether the attribute is recurring. Use only if the attribute's category is 'calculated' or 'global'. This parameter is optional. .PARAMETER enumeration Specifies a list of values and labels that the attribute can take. Use only if the attribute's category is 'category'. This parameter is optional. .PARAMETER multiCategoryOptions Specifies a list of options you want to add for a multiple-choice attribute. Use only if the attribute's category is 'normal' and the attribute's type is 'multiple-choice'. This parameter is optional. .PARAMETER type Specifies the type of the attribute. Valid values are "text", "date", "float", "boolean", "multiple-choice", "id", and "category". The default value is "text". This parameter is optional. .OUTPUTS Returns the created attribute object. .EXAMPLE PS C:\> New-ContactAttribute -attributeCategory "normal" -attributeName "FirstName" -type "text" Creates a new contact attribute with the category "normal", name "FirstName", and type "text". .EXAMPLE PS C:\> New-ContactAttribute -attributeCategory "category" -attributeName "Status" -enumeration @{"Active"="1"; "Inactive"="0"} Creates a new contact attribute with the category "category", name "Status", and an enumeration of values. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Category of the attribute")] [ValidateSet("normal", "transactional", "category", "calculated", "global")] $attributeCategory, [Parameter(Mandatory = $true, HelpMessage = "The name of the attribute")] $attributeName, [Parameter(Mandatory = $false, HelpMessage = "Value of the attribute. Use only if the attribute's category is 'calculated' or 'global'")] [ValidateSet("calculated", "global")] $value, [Parameter(Mandatory = $false, HelpMessage = "Type of the attribute. Use only if the attribute's category is 'calculated' or 'global'")] [ValidateSet("calculated", "global")] $isRecurring, [Parameter(Mandatory = $false, HelpMessage = "List of values and labels that the attribute can take. Use only if the attribute's category is 'category'")] $enumeration, [Parameter(Mandatory = $false, HelpMessage = "List of options you want to add for multiple-choice attribute. Use only if the attribute's category is 'normal' and attribute's type is 'multiple-choice'.")] $multiCategoryOptions, [Parameter(Mandatory = $false, HelpMessage = "Type of the attribute. Use only if the attribute's category is 'normal', 'category' or 'transactional' Type boolean and multiple-choice is only available if the category is normal attribute Type id is only available if the category is transactional attribute Type category is only available if the category is category attribute")] [ValidateSet("text", "date", "float", "boolean", "multiple-choice", "id", "category")] $type = "text" ) $uri = "/contacts/attributes" + "/" + $attributeCategory + "/" + $attributeName $method = "POST" $body = @{} $value ? $(body.value = $value) : $null $isRecurring ? ($body.isRecurring = $isRecurring) : $null $enumeration ? ($body.enumeration = $enumeration) : $null $multiCategoryOptions ? ($body.multiCategoryOptions = $multiCategoryOptions) : $null $body.type = $type $Params = @{ "URI" = $uri "Method" = $method "Body" = $body "returnobject" = "attributes" } try { $attribute = Invoke-BrevoCall @Params $attribute = Get-ContactAttribute -Name $attributeName } catch { } return $attribute } #EndRegion './Public/Contact Management/Attribute/New-ContactAttribute.ps1' 96 #Region './Public/Contact Management/Attribute/Remove-ContactAttribute.ps1' -1 function Remove-ContactAttribute { [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true, HelpMessage = "Category of the attribute", ValueFromPipelineByPropertyName = $true)] [ValidateSet("normal", "transactional", "category", "calculated", "global")] [Alias("AttributeCategory")] [string]$category, [Parameter(Mandatory = $true, HelpMessage = "The name of the contact attribute (case-insensitive)", ValueFromPipelineByPropertyName = $true)] [Alias("AttributeName")] [string]$Name ) process { $method = "DELETE" $uri = "/contacts/attributes/$Category/$Name" $Params = @{ "URI" = $uri "Method" = $method } Write-Host @Params $attribute = Invoke-BrevoCall @Params } } #EndRegion './Public/Contact Management/Attribute/Remove-ContactAttribute.ps1' 25 #Region './Public/Contact Management/Contact/Get-Contact.ps1' -1 function Get-Contact { <# .SYNOPSIS Retrieves contact information from the Brevo API based on specified parameters. .DESCRIPTION The Get-Contact function is used to fetch contact details from the Brevo API. It supports various filters and query parameters to customize the results, such as filtering by ID, creation/modification date, list IDs, segment IDs, and sorting options. .PARAMETER Id The unique identifier for the contact. This can be an email ID (for EMAIL), phone ID (for SMS), or contact ID. .PARAMETER limit Specifies the number of documents per page. Acceptable values are between 0 and 50. Defaults to 10 if not specified. .PARAMETER offset Specifies the number of documents to skip. Acceptable values are between 0 and 50. Defaults to 10 if not specified. .PARAMETER sort Sorts the results in ascending ("asc") or descending ("desc") order of record creation. The default order is "desc". .PARAMETER modifiedSince Filters the contacts modified after a given date-time (local time). The date-time should be URL-encoded. .PARAMETER createdSince Filters the contacts created after a given date-time (local time). The date-time should be URL-encoded. .PARAMETER segmentId Filters the contacts by the ID of the segment. Either `listId` or `segmentId` can be passed. .PARAMETER listId Filters the contacts by the ID(s) of the list(s). Accepts an array of integers. .PARAMETER filter Filters the contacts based on attributes. The allowed operator is `equals`. For multiple-choice options, the filter applies an AND condition between the options. For category attributes, the filter works with both ID and value. Examples: - `filter=equals(FIRSTNAME,"Antoine")` - `filter=equals(B1, true)` - `filter=equals(DOB, "1989-11-23")` - `filter=equals(GENDER, "1")` - `filter=equals(GENDER, "MALE")` - `filter=equals(COUNTRY,"USA, INDIA")` .EXAMPLE # Retrieve a contact by ID Get-Contact -Id "12345" .EXAMPLE # Retrieve contacts created since a specific date Get-Contact -createdSince "2023-01-01" .EXAMPLE # Retrieve contacts with a specific filter Get-Contact -filter 'equals(FIRSTNAME,"John")' .NOTES This function constructs a query string based on the provided parameters and makes a GET request to the Brevo API using the Invoke-BrevoCall function. #> [CmdletBinding()] param ( [Parameter(Mandatory = $false, HelpMessage = "ID is email_id (for EMAIL), phone_id (for SMS) or contact_id (for ID of the contact)")] [string]$Id, [Parameter(Mandatory = $false, HelpMessage = "Email address of the contact. This is mandatory if Id is not provided.")] [string]$email, [Parameter(Mandatory = $false, HelpMessage = "0 to 50. Defaults to 10. Number of documents per page")] [int]$limit, [Parameter(Mandatory = $false, HelpMessage = "Number of documents per page. 0 to 50. Defaults to 10")] [int]$offset, [Parameter(Mandatory = $false, HelpMessage = "Sort the results in the ascending/descending order of record creation. Default order is desc")] [ValidateSet("asc", "desc")] [string]$sort, [Parameter(Mandatory = $false, HelpMessage = "Filter (urlencoded) the contacts modified after a given date-time (local time)")] $modifiedSince, [Parameter(Mandatory = $false, HelpMessage = "Filter (urlencoded) the contacts created after a given date-time (local time)")] $createdSince, [Parameter(Mandatory = $false, HelpMessage = "Id of the segment. Either listIds or segmentId can be passed.")] [int]$segmentId, [Parameter(Mandatory = $false, HelpMessage = "Id of the list(s).")] [int[]]$listId, [Parameter(Mandatory = $false, HelpMessage = 'Filter the contacts on the basis of attributes. Allowed operator: equals. For multiple-choice options, the filter will apply an AND condition between the options. For category attributes, the filter will work with both id and value. (e.g. filter=equals(FIRSTNAME,"Antoine"), filter=equals(B1, true), filter=equals(DOB, "1989-11-23"), filter=equals(GENDER, "1"), filter=equals(GENDER, "MALE"), filter=equals(COUNTRY,"USA, INDIA")')] [string]$filter ) $uri = "/contacts/$([System.Web.HttpUtility]::UrlEncode($Id))" $method = "GET" $queryParams = @{} if ($limit -ne 0) { $queryParams["limit"] = $limit } if ($offset -ne 0) { $queryParams["offset"] = $offset } if (-not [string]::IsNullOrEmpty($sort)) { $queryParams["sort"] = $sort } if ($null -ne $modifiedSince) { $queryParams["modifiedSince"] = [System.Web.HttpUtility]::UrlEncode((Get-Date $modifiedSince).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) } if ($null -ne $createdSince) { $queryParams["createdSince"] = [System.Web.HttpUtility]::UrlEncode((Get-Date $createdSince).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) } if ($segmentId -ne 0) { $queryParams["segmentId"] = $segmentId } if ($listId -is [Array]) { $queryParams["listId"] = $listId -join "," } if ($queryParams.Count -gt 0) { $queryString = ($queryParams.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join "&" $uri = $uri + "?$queryString" } $Params = @{ "URI" = $uri "Method" = $method } $contact = Invoke-BrevoCall @Params return $contact } #EndRegion './Public/Contact Management/Contact/Get-Contact.ps1' 140 #Region './Public/Contact Management/Contact/Import-Contact.ps1' -1 function Import-Contact { # https://developers.brevo.com/reference/importcontacts-1 <# .SYNOPSIS Imports contacts into Brevo using various input formats. .DESCRIPTION The Import-Contact function allows you to import contacts into Brevo using a file URL, CSV content, or JSON content. It supports various parameters to customize the import process, including list IDs, notification URL, new list creation, blacklisting options, and updating existing contacts. .PARAMETER fileUrl URL of the file to be imported (no local file). Possible file formats: .txt, .csv, .json. Mandatory if fileBody and jsonBody are not defined. .PARAMETER fileBody CSV content to be imported. Use semicolon to separate multiple attributes. Maximum allowed file body size is 10MB. Recommended safe limit is around 8 MB. Mandatory if fileUrl and jsonBody are not defined. .PARAMETER jsonBody JSON content to be imported. Maximum allowed file body size is 10MB. Recommended safe limit is around 8 MB. Mandatory if fileUrl and fileBody are not defined. .PARAMETER ListIds The IDs of the lists to which the contacts are added. Mandatory. .PARAMETER notifyUrl URL that will be called once the import process is finished. .PARAMETER newList To create a new list and import the contacts into it, pass the listName and an optional folderId. .PARAMETER emailBlacklist To blacklist all the contacts for email, set this field to true. .PARAMETER smsBlacklist To blacklist all the contacts for SMS, set this field to true. .PARAMETER updateExistingContacts To facilitate the choice to update the existing contacts, set this field to true. .PARAMETER emptyContactsAttributes Defaults to false. To facilitate the choice to erase any attribute of the existing contacts with empty value. If set to true, empty fields in your import will erase any attribute that currently contains data in Brevo. If set to false, empty fields will not affect your existing data (only available if updateExistingContacts is set to true). .EXAMPLE Import-Contact -fileUrl "https://example.com/contacts.csv" -ListIds 1234 .EXAMPLE Import-Contact -fileBody "name;email`nJohn Doe;john@example.com" -ListIds 1234 .EXAMPLE Import-Contact -jsonBody '{"contacts":[{"email":"john@example.com","name":"John Doe"}]}' -ListIds 1234 #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, ParameterSetName = "Uri", HelpMessage = "Mandatory if fileBody and jsonBody is not defined. URL of the file to be imported (no local file). Possible file formats: .txt, .csv, .json")] [ValidatePattern('^(https?|http)://[^\s/$.?#].[^\s]*$')] [string]$fileUrl, [Parameter(Mandatory = $true, ParameterSetName = "File", HelpMessage = "Mandatory if fileUrl and jsonBody is not defined. CSV content to be imported. Use semicolon to separate multiple attributes. Maximum allowed file body size is 10MB . However we recommend a safe limit of around 8 MB to avoid the issues caused due to increase of file body size while parsing. Please use fileUrl instead to import bigger files.")] [string]$fileBody, [Parameter(Mandatory = $true, ParameterSetName = "Json", HelpMessage = "Mandatory if fileUrl and fileBody is not defined. JSON content to be imported. Maximum allowed file body size is 10MB. However we recommend a safe limit of around 8 MB to avoid the issues caused due to increase of file body size while parsing. Please use fileUrl instead to import bigger files.")] $jsonBody, [Parameter(Mandatory = $true, HelpMessage = "The IDs of the lists to which the contacts are added")] [int[]]$ListIds, [Parameter(Mandatory = $false, HelpMessage = 'URL that will be called once the import process is finished. For reference, https://help.brevo.com/hc/en-us/articles/360007666479')] $notifyUrl, [Parameter(Mandatory = $false, HelpMessage = 'To create a new list and import the contacts into it, pass the listName and an optional folderId.')] $newList, [Parameter(Mandatory = $false, HelpMessage = 'To blacklist all the contacts for email, set this field to true.')] [bool]$emailBlacklist, [Parameter(Mandatory = $false, HelpMessage = 'To blacklist all the contacts for SMS, set this field to true.')] [bool]$smsBlacklist, [Parameter(Mandatory = $false, HelpMessage = 'To facilitate the choice to update the existing contacts, set this field to true.')] [bool]$updateExistingContacts, [Parameter(Mandatory = $false, HelpMessage = 'Defaults to false To facilitate the choice to erase any attribute of the existing contacts with empty value. emptyContactsAttributes = true means the empty fields in your import will erase any attribute that currently contain data in Brevo, & emptyContactsAttributes = false means the empty fields will not affect your existing data ( only available if updateExistingContacts set to true )')] [bool]$emptyContactsAttributes ) $method = "POST" $uri = "/contacts/import" $body = @{} $fileUrl ? ($body.fileUrl = $fileUrl) : $null $fileBody ? ($body.fileBody = $fileBody) : $null $jsonBody ? ($body.jsonBody = $jsonBody) : $null $ListIds ? ($body.listIds = $ListIds) : $null $notifyUrl ? ($body.notifyUrl = $notifyUrl) : $null $newList ? ($body.newList = $newList) : $null $emailBlacklist ? ($body.emailBlacklist = $emailBlacklist) : $null $smsBlacklist ? ($body.smsBlacklist = $smsBlacklist) : $null $updateExistingContacts ? ($body.updateExistingContacts = $updateExistingContacts) : $null $emptyContactsAttributes ? ($body.emptyContactsAttributes = $emptyContactsAttributes) : $null $returnobject = "contacts" $Params = @{ "URI" = $uri "Method" = $method "Body" = $body "returnobject" = $returnobject } $result = Invoke-BrevoCall @Params return $result } #EndRegion './Public/Contact Management/Contact/Import-Contact.ps1' 106 #Region './Public/Contact Management/Contact/New-Contact.ps1' -1 <# .SYNOPSIS Creates a new contact in Brevo with the specified details. .DESCRIPTION The `New-Contact` function allows you to create a new contact in Brevo by providing details such as email, list IDs, attributes, and other optional parameters. It supports updating an existing contact if the `-updateEnabled` switch is set. .PARAMETER Email The email address of the contact. This parameter is mandatory. .PARAMETER ext_id An optional external ID to associate with the contact. .PARAMETER ListIds The IDs of the contact list(s) to which the contact will be added. This parameter is optional. .PARAMETER attributes A hashtable containing attributes and their values for the contact. The attributes should be passed in uppercase letters. Ensure the attributes exist in your Brevo account. For example: `-attributes @{"FIRSTNAME"="John"; "LASTNAME"="Doe"}`. .PARAMETER emailBlacklisted A switch to blacklist the contact for emails. This parameter is optional. .PARAMETER smsBlacklisted A switch to blacklist the contact for SMS. This parameter is optional. .PARAMETER updateEnabled A switch to enable updating an existing contact in the same request. Default is `$false`. .PARAMETER smtpBlacklistSender An array of transactional email forbidden senders for the contact. This is only applicable if `-updateEnabled:$true`. .EXAMPLE # Create a new contact with mandatory and optional parameters New-Contact -Email "example@example.com" -ListIds 1,2 -Attributes @{"FIRSTNAME"="John"; "LASTNAME"="Doe"} -updateEnabled .OUTPUTS The id of the created contact. #> function New-Contact { [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The email address of the contact")] [string]$Email, [Parameter(Mandatory = $false, HelpMessage = "Pass your own Id to create a contact.")] [string]$ext_id, [Parameter(Mandatory = $false, HelpMessage = "The IDs of the contact list to which the contact is added")] [int[]]$ListIds, [Parameter(Mandatory = $false, HelpMessage = 'Pass the set of attributes and their values. The attributes parameter should be passed in capital letter while creating a contact. Values that dont match the attribute type (e.g. text or string in a date attribute) will be ignored. These attributes must be present in your Brevo account. For e.g. -Attributes @{"FIRSTNAME"="John"; "LASTNAME"="Doe"}')] $attributes, [Parameter(Mandatory = $false, HelpMessage = "Set this field to blacklist the contact for emails ")] [switch]$emailBlacklisted, [Parameter(Mandatory = $false, HelpMessage = "Set this field to blacklist the contact for SMS")] [switch]$smsBlacklisted, [Parameter(Mandatory = $false, HelpMessage = "Facilitate to update the existing contact in the same request. Default is false.")] [switch]$updateEnabled = $false, [Parameter(Mandatory = $false, HelpMessage = "transactional email forbidden sender for contact. Use only for email Contact ( only available if updateEnabled = true )")] [string[]]$smtpBlacklistSender ) $uri = "/contacts" $method = "POST" $body = @{ email = $Email } if ($ListIds) { $body.listIds = $ListIds } if ($ext_id) { $body.ext_id = $ext_id } if ($attributes) { $attrib = @{} if ($attributes -is [hashtable]) { $attributes.GetEnumerator() | ForEach-Object { $attrib.Add($_.Key, $_.Value) } } else { Write-Error "The 'attributes' parameter must be a hashtable." } $body.attributes = $attrib } $Params = @{ "URI" = $uri "Method" = $method "Body" = $body #"returnobject" = "contacts" } $contact = Invoke-BrevoCall @Params return $contact } #EndRegion './Public/Contact Management/Contact/New-Contact.ps1' 98 #Region './Public/Contact Management/Contact/Remove-Contact.ps1' -1 function Remove-Contact { <# .SYNOPSIS Removes a contact from the system using the specified identifier. .DESCRIPTION The Remove-Contact function deletes a contact from the system based on the provided identifier. The identifier can be an email_id (for EMAIL), phone_id (for SMS), or contact_id (for the ID of the contact). .PARAMETER Identifier The identifier of the contact to be removed. This can be an email_id, phone_id, or contact_id. .EXAMPLE Remove-Contact -Identifier "contact_id_12345" This command removes the contact with the ID "contact_id_12345". .EXAMPLE Remove-Contact -Identifier "email@example.com" This command removes the contact with the email "email@example.com". .NOTES This function supports ShouldProcess for safety, and has a high confirm impact. #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true, HelpMessage = "Identifier is email_id (for EMAIL), phone_id (for SMS) or contact_id (for ID of the contact)", Position = 0, ValueFromPipelineByPropertyName = $true )] [Alias ("Id")] [string]$Identifier ) $uri = "/contacts/$Identifier" $method = "DELETE" $Params = @{ "URI" = $uri "Method" = $method } if ($PSCmdlet.ShouldProcess("$Identifier", "Remove-Contact")) { $contact = Invoke-BrevoCall @Params return $contact } } #EndRegion './Public/Contact Management/Contact/Remove-Contact.ps1' 42 #Region './Public/Contact Management/Contact/Update-Contact.ps1' -1 function Update-Contact { <# .SYNOPSIS Updates a contact in Brevo. .DESCRIPTION This function updates a contact in Brevo using the provided identifier and optional parameters. It supports updating email and SMS blacklisting status, adding and removing contact from lists, and updating contact attributes. .PARAMETER Identifier The identifier of the contact. It can be email_id (for EMAIL), phone_id (for SMS), or contact_id (for ID of the contact). This parameter is mandatory. .PARAMETER ext_id Optional. Pass your own Id to create a contact. .PARAMETER emailBlacklisted Optional. Set/unset this field to blacklist/allow the contact for emails. .PARAMETER smsBlacklisted Optional. Set/unset this field to blacklist/allow the contact for SMS. .PARAMETER ListIds Optional. The IDs of the contact list to which the contact is added. .PARAMETER unlinkListIds Optional. Ids of the lists to remove the contact from. .PARAMETER attributes Optional. Pass the set of attributes and their values. The attributes parameter should be passed in capital letters while creating a contact. Values that don't match the attribute type (e.g., text or string in a date attribute) will be ignored. These attributes must be present in your Brevo account. For example: -Attributes @{"FIRSTNAME"="John"; "LASTNAME"="Doe"} .EXAMPLE PS> Update-Contact -Identifier "contact_id" -emailBlacklisted $true -ListIds @(1,2,3) -attributes @{"FIRSTNAME"="John"; "LASTNAME"="Doe"} This command updates the contact with the specified identifier, sets the email blacklisting status to true, adds the contact to lists with IDs 1, 2, and 3, and updates the contact's first name and last name. .OUTPUTS The function returns the updated contact object. .LINK https://developers.brevo.com/reference/updatecontact https://developers.brevo.com/reference/updatebatchcontacts #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Identifier is email_id (for EMAIL), phone_id (for SMS) or contact_id (for ID of the contact)")] [Alias ("Id")] [string]$Identifier, [Parameter(Mandatory = $false, HelpMessage = "Pass your own Id to create a contact.")] [string]$ext_id, [Parameter(Mandatory = $false, HelpMessage = "Set/unset this field to blacklist/allow the contact for emails")] [bool]$emailBlacklisted, [Parameter(Mandatory = $false, HelpMessage = "Set/unset this field to blacklist/allow the contact for SMS")] [bool]$smsBlacklisted, [Parameter(Mandatory = $false, HelpMessage = "The IDs of the contact list to which the contact is added")] [int[]]$ListIds, [Parameter(Mandatory = $false, HelpMessage = "Ids of the lists to remove the contact from")] [int[]]$unlinkListIds, [Parameter(Mandatory = $false, HelpMessage = 'Pass the set of attributes and their values. The attributes parameter should be passed in capital letter while creating a contact. Values that dont match the attribute type (e.g. text or string in a date attribute) will ) be ignored. These attributes must be present in your Brevo account. For e.g. -Attributes @{"FIRSTNAME"="John"; "LASTNAME"="Doe"}')] $attributes ) $uri = "/contacts/$Identifier" $method = "PATCH" $body = @{} #$isRecurring ? ($body.isRecurring = $isRecurring) : $null $ext_id ? ($body.ext_id = $ext_id) : $null $emailBlacklisted ? ($body.emailBlacklisted = $emailBlacklisted) : $null $smsBlacklisted ? ($body.smsBlacklisted = $smsBlacklisted) : $null $ListIds ? ($body.listIds = $ListIds) : $null $unlinkListIds ? ($body.unlinkListIds = $unlinkListIds) : $null if ($attributes) { $attrib = @{} $attributes | ForEach-Object { $attrib.Add($_.Key, $_.Value) } $body.attributes = $attrib } $Params = @{ "URI" = $uri "Method" = $method "Body" = $body } $contact = Invoke-BrevoCall @Params return $contact } #EndRegion './Public/Contact Management/Contact/Update-Contact.ps1' 89 #Region './Public/Contact Management/Folder/Get-ContactFolder.ps1' -1 function Get-ContactFolder { [CmdletBinding(DefaultParameterSetName = "None")] param ( [Parameter(Mandatory = $false, HelpMessage = "The ID of the folder", ParameterSetName = "ByFolderId")] [int]$folderId, [Parameter(Mandatory = $false, HelpMessage = "The name of the folder to retrieve", ParameterSetName = "ByFolderName")] [string]$Name, [Parameter(Mandatory = $false)] [switch]$None, [Parameter(Mandatory = $false, HelpMessage = "0 to 50. Defaults to 10. Number of documents per page")] [int]$limit, [Parameter(Mandatory = $false, HelpMessage = "Number of documents per page. 0 to 50. Defaults to 10")] [int]$offset, [Parameter(Mandatory = $false, HelpMessage = "Sort the results in the ascending/descending order of record creation. Default order is desc")] [ValidateSet("asc", "desc")] [string]$sort ) $method = "GET" if ($folderId) { $uri = "/contacts/folders/$folderId" } else { $uri = "/contacts/folders" } $queryParams = @{} if ($limit -ne 0) { $queryParams["limit"] = $limit } if ($offset -ne 0) { $queryParams["offset"] = $offset } if (-not [string]::IsNullOrEmpty($sort)) { $queryParams["sort"] = $sort } if ($queryParams.Count -gt 0) { $queryString = ($queryParams.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join "&" $uri = $uri + "?$queryString" } #$returnobject = "folders" $Params = @{ "URI" = $uri "Method" = $method # "returnobject" = $returnobject } $folders = Invoke-BrevoCall @Params if ($Name) { $folders = $folders | Where-Object { $_.name -eq $Name } } return $folders } #EndRegion './Public/Contact Management/Folder/Get-ContactFolder.ps1' 63 #Region './Public/Contact Management/Folder/New-ContactFolder.ps1' -1 function New-ContactFolder { <# .SYNOPSIS Creates a new contact folder in Brevo. .DESCRIPTION The New-ContactFolder function creates a new contact folder in Brevo by sending a POST request to the /contacts/folders endpoint. .PARAMETER Name The name of the contact folder to be created. This parameter is mandatory. .EXAMPLE PS C:\> New-ContactFolder -Name "MyNewFolder" This command creates a new contact folder named "MyNewFolder". .OUTPUTS The function returns the created contact folder object. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The name of the contact folder")] [string]$Name ) $uri = "/contacts/folders" $method = "POST" $body = @{ name = $Name } $Params = @{ "URI" = $uri "Method" = $method "Body" = $body # "returnobject" = "folders" } $folder = Invoke-BrevoCall @Params if ($folder -and ($folder.id -ne $null)) { $folder = Get-ContactFolder -folderId $folder.id } return $folder } #EndRegion './Public/Contact Management/Folder/New-ContactFolder.ps1' 42 #Region './Public/Contact Management/Folder/Remove-ContactFolder.ps1' -1 function Remove-ContactFolder { <# .SYNOPSIS Removes a contact folder by its ID. .DESCRIPTION The Remove-ContactFolder function deletes a contact folder identified by its ID. It uses the DELETE HTTP method to send a request to the specified URI. .PARAMETER folderId The unique identifier of the folder to be removed. This parameter is mandatory and accepts a string value. It can also be provided via pipeline by property name. .INPUTS System.String The function accepts a string input for the folderId parameter. .OUTPUTS System.Object Returns the response object from the Invoke-BrevoCall function. .EXAMPLE Remove-ContactFolder -folderId "12345" This command removes the contact folder with the ID "12345". .EXAMPLE "12345" | Remove-ContactFolder This command removes the contact folder with the ID "12345" by passing the ID through the pipeline. .EXAMPLE Get-ContactFolder -folderId "12345" | Remove-ContactFolder This command retrieves the contact folder with the ID "12345" and then removes it. .NOTES - This function supports ShouldProcess for safety, allowing you to confirm the action before it is executed. - ConfirmImpact is set to 'High', so you may be prompted for confirmation depending on your PowerShell settings. #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param ( [Parameter(Mandatory = $true, HelpMessage = "Id of the folder", Position = 0, ValueFromPipelineByPropertyName = $true )] [Alias ("Id")] [string]$folderId ) $uri = "/contacts/folders/$folderId" $method = "DELETE" $Params = @{ "URI" = $uri "Method" = $method } if ($PSCmdlet.ShouldProcess("$Identifier", "Remove-ContactFolder")) { $contact = Invoke-BrevoCall @Params return $contact } } #EndRegion './Public/Contact Management/Folder/Remove-ContactFolder.ps1' 59 #Region './Public/Contact Management/List/Add-ContactListMember.ps1' -1 function Add-ContactListMember { <# .SYNOPSIS Adds members to a specified contact list in Brevo. .DESCRIPTION The Add-ContactListMember function allows you to add contacts to a specific contact list in Brevo. You can add contacts using their email addresses, IDs, or external IDs (EXTID attributes). The function supports adding up to 150 contacts in a single request. .PARAMETER listId The ID of the contact list to update. This parameter is mandatory. .PARAMETER emails An array of email addresses to add to the contact list. This parameter is mandatory when using the "AddContactToListByEmails" parameter set. You can pass a maximum of 150 email addresses in one request. .PARAMETER ids An array of contact IDs to add to the contact list. This parameter is optional and used with the "AddContactToListByIds" parameter set. You can pass a maximum of 150 IDs in one request. .PARAMETER extids An array of external IDs (EXTID attributes) to add to the contact list. This parameter is optional and used with the "AddContactToListByExtIds" parameter set. You can pass a maximum of 150 EXTID attributes in one request. .OUTPUTS Object Returns the updated (success/failure) contact list object. .EXAMPLE # Example 1: Add contacts to a list using email addresses Add-ContactListMember -listId 123 -emails @("example1@example.com", "example2@example.com") # Example 2: Add contacts to a list using contact IDs Add-ContactListMember -listId 123 -ids @(101, 102, 103) # Example 3: Add contacts to a list using external IDs Add-ContactListMember -listId 123 -extids @(201, 202, 203) .NOTES - Ensure that you provide at least one of the parameters: emails, ids, or extids. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The ID of the contact list to update")] [int]$listId, [Parameter(Mandatory = $true, HelpMessage = "array of strings. Length between 1 and 150. Emails to add to a list. You can pass a maximum of 150 emails for addition in one request.", ParameterSetName = "AddContactToListByEmails")] [string[]]$emails, [Parameter(Mandatory = $false, HelpMessage = "IDs to add to a list. You can pass a maximum of 150 IDs for addition in one request.", ParameterSetName = "AddContactToListByIds")] [int[]]$ids, [Parameter(Mandatory = $false, HelpMessage = "EXTID attributes to add to a list. You can pass a maximum of 150 EXT_ID attributes for addition in one request.", ParameterSetName = "AddContactToListByExtIds")] [int[]]$extids ) $uri = "/contacts/lists/$listId/contacts/add" $method = "POST" $body = @{} if ($emails) { $body = @{ emails = $emails } } elseif ($ids) { $body = @{ ids = $ids } } elseif ($extids) { $body = @{ extIds = $extids } } else { Write-Error "Please provide either emails, ids or extids." return } $Params = @{ "URI" = $uri "Method" = $method "Body" = $body "returnobject" = "contacts" } $list = Invoke-BrevoCall @Params return $list } #EndRegion './Public/Contact Management/List/Add-ContactListMember.ps1' 90 #Region './Public/Contact Management/List/Get-ContactList.ps1' -1 function Get-ContactList { <# .SYNOPSIS Retrieves contact lists or a specific contact list from Brevo. .DESCRIPTION The Get-ContactList function retrieves contact lists or a specific contact list based on the provided parameters. It supports filtering by list ID, folder ID, or retrieving all lists with optional pagination and sorting. .PARAMETER listId The ID of the specific contact list to retrieve. Used with the "ByListId" parameter set. .PARAMETER folderId The ID of the folder to retrieve contact lists from. Used with the "ByFolderId" parameter set. .PARAMETER listName The name of the contact list to retrieve. .PARAMETER limit The maximum number of documents to retrieve per page. Accepts values from 0 to 50. Defaults to 10. .PARAMETER offset The index of the first document of the page. Defaults to 0. .PARAMETER sort The sorting criteria for the retrieved contact lists. .EXAMPLE # Retrieve all contact lists with default pagination Get-ContactList .EXAMPLE # Retrieve a specific contact list by its ID Get-ContactList -listId 123 .EXAMPLE # Retrieve contact lists from a specific folder Get-ContactList -folderId 456 .EXAMPLE # Retrieve contact lists with pagination Get-ContactList -limit 20 -offset 10 .OUTPUTS Returns a list of contact lists or a specific contact list based on the provided parameters. #> [CmdletBinding(DefaultParameterSetName = "None")] param ( [Parameter(Mandatory = $false, HelpMessage = "The ID of the list", ParameterSetName = "ByListId")] [Alias("Id")] [int]$listId, [Parameter(Mandatory = $false, HelpMessage = "The ID of the folder to retrieve lists from", ParameterSetName = "ByFolderId")] [int]$folderId, [Parameter(Mandatory = $false, HelpMessage = "The ID of the folder to retrieve lists from", ParameterSetName = "ByFolderId")] [Parameter(Mandatory = $false, HelpMessage = "The ID of the folder to retrieve lists from", ParameterSetName = "None")] [Alias("Name")] [string]$listName, [Parameter(Mandatory = $false, ParameterSetName = "None", HelpMessage = "No specific filter applied")] [switch]$None, [Parameter(Mandatory = $false, HelpMessage = "0 to 50. Defaults to 10. Number of documents per page")] [int]$limit, [Parameter(Mandatory = $false, HelpMessage = "Number of documents per page. 0 to 50. Defaults to 10")] [int]$offset, [Parameter(Mandatory = $false, HelpMessage = "Sort the results in the ascending/descending order of record creation. Default order is desc")] [ValidateSet("asc", "desc")] [string]$sort ) $method = "GET" if ($listId) { $uri = "/contacts/lists/$listId" $method = "GET" } else { $uri = "/contacts/lists" $method = "GET" } if ($folderId) { $uri = "/contacts/folders/$folderId/lists" } $queryParams = @{} if ($limit -ne 0) { $queryParams["limit"] = $limit } if ($offset -ne 0) { $queryParams["offset"] = $offset } if (-not [string]::IsNullOrEmpty($sort)) { $queryParams["sort"] = $sort } if ($queryParams.Count -gt 0) { $queryString = ($queryParams.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join "&" $uri = $uri + "?$queryString" } $params = @{ "URI" = $uri "Method" = $method # "returnobject" = "lists" } $list = Invoke-BrevoCall @params if (-not [string]::IsNullOrEmpty($listName)) { $list = $list | Where-Object { $_.name -eq $listName } } #TODO: Count is wrong if $list is empty return $list } #EndRegion './Public/Contact Management/List/Get-ContactList.ps1' 116 #Region './Public/Contact Management/List/Get-ContactListMember.ps1' -1 function Get-ContactListMember { <# .SYNOPSIS Retrieves members of a specified contact list. .DESCRIPTION The Get-ContactListMember function retrieves the members of a contact list based on the provided list ID. Optional parameters allow filtering by modification date, limiting the number of results, specifying an offset, and sorting the results. .PARAMETER listId The ID of the contact list to retrieve members from. This parameter is mandatory. .PARAMETER modifiedSince Filters the contacts modified after a given UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ). It is recommended to pass your timezone in date-time format for accurate results. This parameter is optional. .PARAMETER limit Specifies the number of documents per page. Acceptable values are between 0 and 500. Defaults to 50 if not provided. This parameter is optional. .PARAMETER offset Specifies the index of the first document of the page. This parameter is optional. .PARAMETER sort Sorts the results in ascending or descending order of record creation. If not provided, the default order is descending. This parameter is optional. .EXAMPLE Get-ContactListMember -listId 12345 -modifiedSince "2023-01-01T00:00:00.000Z" -limit 100 -offset 0 -sort "asc" This example retrieves up to 100 members of the contact list with ID 12345, modified after January 1, 2023, starting from the first record, sorted in ascending order. .RETURNS Returns the list of contacts retrieved from the specified contact list. .NOTES This function uses the Invoke-BrevoCall cmdlet to make the API call to retrieve the contact list members. Ensure that the Invoke-BrevoCall cmdlet is properly configured and available in your environment. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The ID of the contact list to update")] [int]$listId, [Parameter(Mandatory = $false, HelpMessage = "Filter (urlencoded) the contacts modified after a given UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ). Prefer to pass your timezone in date-time format for accurate result.")] [string]$modifiedSince, [Parameter(Mandatory = $false, HelpMessage = "0 to 500. Defaults to 50 Number of documents per page")] [int]$limit, [Parameter(Mandatory = $false, HelpMessage = "Index of the first document of the page")] [int]$offset, [Parameter(Mandatory = $false, HelpMessage = "Sort the results in the ascending/descending order of record creation. Default order is descending if sort is not passed")] [string]$sort ) $uri = "/contacts/lists/$listId/contacts" $method = "GET" if ($limit -ne 0) { $queryParams["limit"] = $limit } if ($offset -ne 0) { $queryParams["offset"] = $offset } if (-not [string]::IsNullOrEmpty($sort)) { $queryParams["sort"] = $sort } if ($queryParams.Count -gt 0) { $queryString = ($queryParams.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join "&" $uri = $uri + "?$queryString" } $Params = @{ "URI" = $uri "Method" = $method } $contacts = Invoke-BrevoCall @Params return $contacts } #EndRegion './Public/Contact Management/List/Get-ContactListMember.ps1' 83 #Region './Public/Contact Management/List/New-ContactList.ps1' -1 function New-ContactList { <# .SYNOPSIS Creates a new contact list in Brevo. .DESCRIPTION The New-ContactList function creates a new contact list in Brevo by specifying the name of the contact list and the ID of the folder in which the contact list is created. .PARAMETER Name The name of the contact list. .PARAMETER FolderId The ID of the folder in which the contact list is created. .EXAMPLE $contactList = New-ContactList -Name "My New List" -FolderId 123 Creates a new contact list named "My New List" in the folder with ID 123. .OUTPUTS The created contact list object. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The name of the contact list")] [string]$Name, [Parameter(Mandatory = $true, HelpMessage = "The ID of the folder in which the contact list is created")] $FolderId ) $uri = "/contacts/lists" $method = "POST" $body = @{ name = $Name folderId = $FolderId } $Params = @{ "URI" = $uri "Method" = $method "Body" = $body "returnobject" = "lists" } try { Invoke-BrevoCall @Params $params = @{ Name = $Name } if ($null -ne $FolderId) { $params.FolderId = $FolderId } $list = Get-ContactList @params } catch { } return $list } #EndRegion './Public/Contact Management/List/New-ContactList.ps1' 58 #Region './Public/Contact Management/List/Remove-ContactList.ps1' -1 function Remove-ContactList { <# .SYNOPSIS Removes a contact list by its ID. .DESCRIPTION The Remove-ContactList function deletes a contact list identified by its unique ID. It sends a DELETE request to the specified URI endpoint. .PARAMETER listId The ID of the contact list to delete. This parameter is mandatory. .EXAMPLE Remove-ContactList -listId 12345 This command deletes the contact list with the ID 12345. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The ID of the contact list to delete")] [int]$listId ) $uri = "/contacts/lists/$listId" $method = "DELETE" $Params = @{ "URI" = $uri "Method" = $method } $list = Invoke-BrevoCall @Params return $list } #EndRegion './Public/Contact Management/List/Remove-ContactList.ps1' 32 #Region './Public/Contact Management/List/Update-ContactList.ps1' -1 function Update-ContactList { <# .SYNOPSIS Updates a contact list by modifying its name or moving it to a different folder. .DESCRIPTION The `Update-ContactList` function allows you to update the properties of an existing contact list. You can either update the name of the list or move it to a different folder by specifying the folder ID. Only one of these properties (name or folderId) can be updated at a time. .PARAMETER listId The ID of the contact list to update. This parameter is mandatory. .PARAMETER Name The new name for the contact list. This parameter is optional. If specified, the list's name will be updated. .PARAMETER folderid The ID of the folder to which the contact list should be moved. This parameter is optional. If specified, the list will be moved to the specified folder. .EXAMPLE # Update the name of a contact list with ID 123 Update-ContactList -listId 123 -Name "New List Name" .EXAMPLE # Move a contact list with ID 456 to a folder with ID 789 Update-ContactList -listId 456 -folderid 789 #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The ID of the contact list to update")] [int]$listId, [Parameter(Mandatory = $false, HelpMessage = "Name of the list. Either of the two parameters (name, folderId) can be updated at a time.")] [string]$Name, [Parameter(Mandatory = $false, HelpMessage = "Id of the folder in which the list is to be moved. Either of the two parameters (name, folderId) can be updated at a time.")] [int]$folderid ) $uri = "/contacts/lists/$listId" $method = "PUT" $body = @{} if ($Name) { $body.name = $Name } if ($folderid) { $body.folderId = $folderid } $Params = @{ "URI" = $uri "Method" = $method "Body" = $body } $list = Invoke-BrevoCall @Params return $list } #EndRegion './Public/Contact Management/List/Update-ContactList.ps1' 61 #Region './Public/Contact Management/Segment/Get-ContactSegment.ps1' -1 function Get-ContactSegment { <# .SYNOPSIS Retrieves contact segments from the Brevo API. .DESCRIPTION The Get-ContactSegment function retrieves contact segments from the Brevo API. It allows you to specify the number of results per page, the starting index for pagination, and the sort order of the results. .PARAMETER limit The number of results returned per page. The default is 10, and the maximum is 50. .PARAMETER offset The index of the first document in the page (starting with 0). For example, if the limit is 50 and you want to retrieve page 2, then offset=50. .PARAMETER sort Sorts the results in the ascending ("asc") or descending ("desc") order of record creation. The default order is descending if this parameter is not specified. .EXAMPLE Get-ContactSegment -limit 20 -offset 0 -sort "asc" Retrieves the first 20 contact segments sorted in ascending order. .EXAMPLE Get-ContactSegment -limit 50 -offset 100 Retrieves 50 contact segments starting from the 101st record, sorted in descending order. #> [CmdletBinding()] param ( [Parameter(Mandatory = $false, HelpMessage = "The number of results returned per page. The default is 10. The maximum is 50")] [int]$limit = 10, [Parameter(Mandatory = $false, HelpMessage = "The index of the first document in the page (starting with 0). For example, if the limit is 50 and you want to retrieve the page 2, then offset=50")] [int]$offset = 0, [Parameter(Mandatory = $false, HelpMessage = "Sort the results in the ascending/descending order of record creation. Default order is descending if sort is not passed")] [ValidateSet ("asc", "desc")] [string]$sort = "desc" ) $method = "GET" $uri = "/contacts/segments" #$returnobject = "segments" $queryParams = @{} if ($null -ne $limit) { $queryParams["limit"] = $limit } if ($null -ne $offset) { $queryParams["offset"] = $offset } if ($queryParams.Count -gt 0) { $queryString = ($queryParams.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }) -join "&" $uri = $uri + "?$queryString" } $Params = @{ "URI" = $uri "Method" = $method # "returnobject" = $returnobject } $folder = Invoke-BrevoCall @Params return $folder } #EndRegion './Public/Contact Management/Segment/Get-ContactSegment.ps1' 68 #Region './Public/Disconnect-Brevo.ps1' -1 <# .SYNOPSIS Disconnects from the Brevo API by clearing the stored API URI and API key. .DESCRIPTION The `Disconnect-Brevo` function clears the global variables `$script:APIuri` and `$script:APIkey`, effectively disconnecting from the Brevo API. It also provides a confirmation message indicating the disconnection. .EXAMPLE Disconnect-Brevo This command disconnects the current session from the Brevo API and displays a confirmation message. .OUTPUTS True if the disconnection was successful, otherwise nothing. #> function Disconnect-Brevo { [CmdletBinding()] [OutputType([bool])] param() $script:APIuri = $null $script:APIkey = $null Write-Host -ForegroundColor Green "Disconnected from Brevo API" return $true } #EndRegion './Public/Disconnect-Brevo.ps1' 28 #Region './Public/Invoke-BrevoCall.ps1' -1 function Invoke-BrevoCall { [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "The URI of the API call. This should be the relative URI to the base URI provided in Connect-Brevo")] [string]$uri, [Parameter(Mandatory = $false, HelpMessage = "The HTTP method to use for the API call")] [ValidateSet("GET", "POST", "PUT", "DELETE", "PATCH") ] $method = "GET", [Parameter(ParameterSetName = "Body")] [System.Object]$body, [Parameter(HelpMessage = "The number of results returned per page. The default and maximum value may vary per API")] $limit, [Parameter(HelpMessage = "The index of the first document in the page (starting with 0). For example, if the limit is 50 and you want to retrieve the page 2, then offset=50")] $offset = 0, [Parameter(HelpMessage = "The object with should be returned, if empty the full response will be returned")] $returnobject ) Write-Debug ($PsBoundParameters | Out-String) Write-Debug ($args | Out-String) if ([string]::IsNullOrEmpty($script:APIuri)) { throw "Please connect first to the Brevo API using Connect-Brevo" } if ($uri -notlike "$script:APIuri*") { Write-Debug "$($MyInvocation.MyCommand):relative path provided" $urifull = ($script:apiuri + $uri).TrimEnd('/') Write-Debug "$($MyInvocation.MyCommand):urifull: $urifull" } else { Write-Debug "$($MyInvocation.MyCommand):absolute path provided" $urifull = $uri } if ($limit) { $urifull += "?limit=$limit" } if ($offset -ne 0) { Write-Debug "$($MyInvocation.MyCommand):Offset: $offset" if (-not $urifull.Contains('?')) { Write-Debug "No ? in URI" $urifull += "?offset=$offset" } else { Write-Debug "$($MyInvocation.MyCommand):URI contains ?" $urifull += "&offset=$offset" } } Write-Debug "urifull: $urifull" $Params = @{ "URI" = $urifull Headers = @{ "api-key" = $script:APIkey.GetNetworkCredential().Password "content-type" = "application/json" "Accept" = "application/json" } "Method" = $method } if ($body) { $Params.Add("Body", ($body | ConvertTo-Json -EnumsAsStrings -Depth 20)) } $result = $null try { Write-Debug "Offset: $offset" do { Write-Debug "URI: $($Params.URI)" $loop = $true $Error.clear() $content = Invoke-RestMethod @Params -ResponseHeadersVariable responseheaders -StatusCodeVariable StatusCodeVariable -ErrorAction Stop Write-Debug "" Write-Debug "PropertyCount: $(($content.PSObject.Properties| Tee-Object -Variable Name | Measure-Object).count)" Write-Debug "Content: $($content |Select-Object * | Out-String)" Write-Debug "Property Count: $($content.count)" if ((($content.PSObject.Properties | Tee-Object -Variable name | Measure-Object).count -eq 2) -and ($content.PSObject.Properties.Name -contains "Count")) { $Property = ($content.PSObject.Properties | Where-Object { $_.Name -ne 'count' }).name $offset = $offset + ($content.$Property).count $result = $result + $content.$Property Write-Debug "Offset: $offset" #TODO: limit auf 1000 setzten um nicht so of loopen zu müssen if ($Params.URI -notlike "*offset*") { if ($Params.URI -notlike '*?*') { $Params.URI += "?offset=$offset" } else { $Params.URI += "?offset=$offset" } } else { $Params.URI = $Params.URI -replace "offset=\d+", "offset=$offset" } } else { $result = $content $loop = $false Write-Debug "No property count - ending loop" Write-Debug "result: $($result | Out-String)" } } while (($loop -eq $true) -and ($offset -lt $content.Count)) # return $result if ($returnobject) { Write-Debug "Returnobject: $returnobject" return $result.$returnobject } else { Write-Debug "No returnobject specified" return $result } } catch { throw $_.Exception.Message # $e = Get-Error -Newest 1 # if ($e.TargetObject.Message) { # $e.TargetObject.Message | ConvertFrom-Json | Out-String | Write-Error # } } } #EndRegion './Public/Invoke-BrevoCall.ps1' 119 #Region './Public/Marketing/Email Campains/Get-EmailCampaign.ps1' -1 function Get-EmailCampaign { <# .SYNOPSIS Retrieves email campaigns based on specified filters. .DESCRIPTION The Get-EmailCampaign function retrieves email campaigns from the Brevo API based on various optional filters such as type, status, statistics, date range, and more. .PARAMETER id The ID(s) of the specific campaign to retrieve. If not specified, all campaigns are retrieved. .PARAMETER name The name(s) of the specific campaign to retrieve. If not specified, all campaigns are retrieved. .PARAMETER type Filter on the type of the campaigns. Valid values are "classic" and "trigger". .PARAMETER status Filter on the status of the campaign. Valid values are "suspended", "archive", "sent", "queued", "draft", and "inProgress". .PARAMETER statistics Filter on the type of statistics required. Valid values are "globalStats", "linkStats", and "statsByDomain". This option only returns data for events occurred in the last 6 months. .PARAMETER startDate Mandatory if endDate is used. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the sent email campaigns. Prefer to pass your timezone in date-time format for accurate result. Only available if either 'status' is not passed or if passed is set to 'sent'. .PARAMETER endDate Mandatory if startDate is used. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the sent email campaigns. Prefer to pass your timezone in date-time format for accurate result. Only available if either 'status' is not passed or if passed is set to 'sent'. .PARAMETER limit Number of documents per page. Defaults to 50. Valid range is 0 to 100. .PARAMETER offset Index of the first document in the page. Defaults to 0. .PARAMETER sort Sort the results in the ascending/descending order of record creation. Default order is descending if sort is not passed. .PARAMETER excludeHtmlContent Use this flag to exclude htmlContent from the response body. If set to true, htmlContent field will be returned as an empty string in the response body. .EXAMPLE Get-EmailCampaign -type "classic" -status "sent" -startDate "2023-01-01T00:00:00.000Z" -endDate "2023-01-31T23:59:59.999Z" .EXAMPLE Get-EmailCampaign -statistics "globalStats" -limit 10 -offset 0 -sort "asc" .OUTPUTS Returns the email campaigns that match the specified filters. #> [CmdletBinding()] param( [Parameter(Mandatory = $false, HelpMessage = "The Id(s) of the campaign")] [int[]]$id, [Parameter(Mandatory = $false, HelpMessage = "The name(s) of the campaign")] [string[]]$name, [Parameter(Mandatory = $false, HelpMessage = "Filter on the type of the campaigns")] [ValidateSet("classic", "trigger")] [string]$type, [Parameter(Mandatory = $false, HelpMessage = "Filter on the status of the campaign")] [ValidateSet("suspended", "archive", "sent", "queued", "draft", "inProgress")] [string]$status, [Parameter(Mandatory = $false, HelpMessage = "Filter on the type of statistics required. Example globalStats value will only fetch globalStats info of the campaign in returned response.This option only returns data for events occurred in the last 6 months.For older campaigns, it’s advisable to use the Get Campaign Report endpoint.")] [ValidateSet("globalStats", "linkStats", "statsByDomain")] [string]$statistics, [Parameter(Mandatory = $false, HelpMessage = "Mandatory if endDate is used. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the sent email campaigns. Prefer to pass your timezone in date-time format for accurate result ( only available if either 'status' not passed and if passed is set to 'sent' )")] [string]$startDate, [Parameter(Mandatory = $false, HelpMessage = "Mandatory if startDate is used. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the sent email campaigns.Prefer to pass your timezone in date-time format for accurate result ( only available if either 'status' not passed and if passed is set to 'sent' )")] [string]$endDate, [Parameter(Mandatory = $false, HelpMessage = "0 to 100 Defaults to 50. Number of documents per page")] [string]$limit, [Parameter(Mandatory = $false, HelpMessage = "Defaults to 0 Index of the first document in the page")] [int]$offset, [Parameter(Mandatory = $false, HelpMessage = "Defaults to desc Sort the results in the ascending/descending order of record creation. Default order is descending if sort is not passed")] [string]$sort, [Parameter(Mandatory = $false, HelpMessage = "Use this flag to exclude htmlContent from the response body. If set to true, htmlContent field will be returned as empty string in the response body")] [bool]$excludeHtmlContent ) $uri = "/emailCampaigns" $body = @{} #$value ? $(body.value = $value) : $null $type ? ($body.type = $type) : $null $status ? ($body.status = $status) : $null $statistics ? ($body.statistics = $statistics) : $null $startDate ? ($body.startDate = $startDate) : $null $endDate ? ($body.endDate = $endDate) : $null $limit ? ($body.limit = $limit) : $null $offset ? ($body.offset = $offset) : $null $sort ? ($body.sort = $sort) : $null $excludeHtmlContent ? ($body.excludeHtmlContent = $excludeHtmlContent) : $null $Params = @{ "URI" = $uri "Method" = "GET" "Body" = $body # "returnobject" = "campaigns" } $emailCampaign = Invoke-BrevoCall @Params if ($id) { $emailCampaign = $emailCampaign | Where-Object { $id -contains $_.id } } if ($name) { $emailCampaign = $emailCampaign | Where-Object { $name -contains $_.name } } return $emailCampaign } #EndRegion './Public/Marketing/Email Campains/Get-EmailCampaign.ps1' 109 #Region './Public/Marketing/Email Campains/Remove-EmailCampaign.ps1' -1 function Remove-EmailCampaign { <# .SYNOPSIS Removes an email campaign by its ID. .DESCRIPTION The Remove-EmailCampaign function deletes an email campaign specified by the campaign ID. It sends a DELETE request to the Brevo API to remove the campaign. .PARAMETER campaignId The ID of the campaign to be deleted. This parameter is mandatory. .EXAMPLE Remove-EmailCampaign -campaignId "12345" This command deletes the email campaign with the ID "12345". .OUTPUTS #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param( [Parameter(Mandatory = $true, HelpMessage = "ID of the campaign to be deleted", ValueFromPipelineByPropertyName = $true)] [Alias("Id")] [string]$campaignId #TODO ) $uri = "/emailCampaigns/$id" $Params = @{ "URI" = $uri "Method" = "DELETE" } if ($PSCmdlet.ShouldProcess("$campaignId", "Remove-EmailCampaign")) { $emailCampaign = Invoke-BrevoCall @Params return $emailCampaign } } #EndRegion './Public/Marketing/Email Campains/Remove-EmailCampaign.ps1' 39 #Region './Public/Marketing/Email Campains/Send-EmailCampaign.ps1' -1 function Send-EmailCampaign { <# .SYNOPSIS Sends an email campaign immediately using the Sendinblue API. .DESCRIPTION The Send-EmailCampaign function sends an email campaign specified by the campaign ID immediately using the Sendinblue API. The function constructs the API endpoint URL using the provided campaign ID and makes a POST request to the Sendinblue API to trigger the campaign. .PARAMETER campaignId The ID of the campaign to be sent. This parameter is mandatory. .EXAMPLE Send-EmailCampaign -campaignId "12345" This example sends the email campaign with the ID "12345" immediately. .OUTPUTS Returns the email campaign object. #> [CmdletBinding()] param( [Parameter(Mandatory = $true, HelpMessage = "ID of the campaign to be sent")] [string]$campaignId ) $uri = "https://api.sendinblue.com/v3/emailCampaigns/$campaignId/sendNow" $Params = @{ "URI" = $uri "Method" = "POST" } $emailCampaign = Invoke-BrevoCall @Params return $emailCampaign } #EndRegion './Public/Marketing/Email Campains/Send-EmailCampaign.ps1' 33 |