function GetContactsFromListBrevo { [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$IdListe ) if (-not $Global:ApiKey) { return [PSCustomObject]@{ Success = $false; Value = "La clé API n'est pas définie" } } $headers = @{ "accept" = "application/json" "api-key" = $Global:ApiKey } try { $response = Invoke-WebRequest ` -Uri "https://api.brevo.com/v3/contacts/lists/$($IdListe)/contacts?limit=50&offset=0&sort=desc" ` -Method GET ` -Headers $headers $data = $response.Content | ConvertFrom-Json return [PSCustomObject]@{ Success = $true Value = $data } } catch { return [PSCustomObject]@{ Success = $false Value = "Erreur lors de la récupération des contacts de la liste $IdListe : $($_.Exception.Message)" } } } function AddContactToBrevo{ [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Email ) if (-not $Global:ApiKey) { return [PSCustomObject]@{ Success = $false; Value = "La clé API n'est pas définie" } } $headers = @{ "accept" = "application/json" "content-type" = "application/json" "api-key" = $Global:ApiKey } $Body = @{ email = $Email } | ConvertTo-Json -Depth 3 try { $response = Invoke-WebRequest -Uri 'https://api.brevo.com/v3/contacts' ` -Method POST ` -Headers $headers ` -ContentType 'application/json' ` -Body $Body return [PSCustomObject]@{ Success = $true; Value = $response.Content } } catch { return [PSCustomObject]@{ Success = $false; Value = "Erreur lors de l'ajout de l'utilisateur $Email : $($_.Exception.Message)" } } } function AddContactBrevoToList{ [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Email, [Parameter(Mandatory=$true)] [string]$IdListe ) if (-not $Global:ApiKey) { return [PSCustomObject]@{ Success = $false; Value = "La clé API n'est pas définie" } } $headers = @{ "accept" = "application/json" "content-type" = "application/json" "api-key" = $Global:ApiKey } $Body = @{ emails = @($Email) } | ConvertTo-Json -Depth 3 try { $response = Invoke-WebRequest -Uri "https://api.brevo.com/v3/contacts/lists/$IdListe/contacts/add" ` -Method POST ` -Headers $headers ` -ContentType 'application/json' ` -Body $Body return [PSCustomObject]@{ Success = $true; Value = $response.Content } } catch { return [PSCustomObject]@{ Success = $false; Value = "Erreur lors de l'ajout de l'utilisateur $Email à la liste $IdListe : $($_.Exception.Message)" } } } function RemoveContactFromListBrevo{ [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Email, [Parameter(Mandatory=$true)] [string]$IdListe ) if (-not $Global:ApiKey) { return [PSCustomObject]@{ Success = $false; Value = "La clé API n'est pas définie" } } $headers = @{ "accept" = "application/json" "content-type" = "application/json" "api-key" = $Global:ApiKey } $Body = @{ emails = @($Email) } | ConvertTo-Json -Depth 3 try { $response = Invoke-WebRequest -Uri "https://api.brevo.com/v3/contacts/lists/$IdListe/contacts/remove" ` -Method POST ` -Headers $headers ` -ContentType 'application/json' ` -Body $Body return [PSCustomObject]@{ Success = $true; Value = $response.Content } } catch { return [PSCustomObject]@{ Success = $false; Value = "Erreur lors de la suppresion de l'utilisateur $Email à la liste $IdListe : $($_.Exception.Message)" } } } function RemoveContactFromBrevo{ [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Email ) if (-not $Global:ApiKey) { return [PSCustomObject]@{ Success = $false; Value = "La clé API n'est pas définie" } } $headers = @{ "accept" = "application/json" "content-type" = "application/json" "api-key" = $Global:ApiKey } try { $response = Invoke-WebRequest -Uri "https://api.brevo.com/v3/contacts/$Email" ` -Method DELETE ` -Headers $headers ` -ContentType 'application/json' return [PSCustomObject]@{ Success = $true; Value = $response.Content } } catch { return [PSCustomObject]@{ Success = $false; Value = "Erreur lors de la suppresion de l'utilisateur $Email à la liste $IdListe : $($_.Exception.Message)" } } }