help with api
Question asked by Keith Dovale - 3/7/2024 at 3:14 AM
I am busy with a powershell script that gives me all the blocked ips on my smartermail servers, I have added code to use the "unblockip" call, it says the ip was removed successfully but the ip isnt removed.

the api documentation gives this 
var input_blacklist? = "INPUT DATA";
var input_post = { INPUT DATA HERE };
var url = SmarterMailUrl + "api/v1/settings/sysadmin/unblock-ips/" + input_blacklist? + "";

    url: url,
    type: 'POST',
    data: input_post,
    dataType: 'json',
    success: function (data) {
        // Do something with data here

My question is as follows, when it comes to this api the documentation inst very specific as to the payload etc, is this apicall even to remove ips from the ids blocklist ?

1) what is input_blacklist? supposed to be ? Ie the ip address or the service name etc ? 

2) am i supposed to provide just the ip address or the ip and service name etc ? 

            $unblockPayload = @{
                ipBlocks = @(
                        ip = $selectedIP
                        count = 0
                        protocol = 0    # Protocol enum value (e.g., SMTP)
                        blockType = 0   # Block type enum value (e.g., Undefined)
                        serviceType = 0 # Service type enum value (e.g., Smtp)

            # Unblock the selected IP
            write-host "$unblockResponse = Invoke-RestMethod -Uri ($unblockIPsUrl+"POP?"+$selectedIP) -Method Post -Headers $headers -ContentType "application/json" -Body ($unblockPayload | ConvertTo-Json)"
            $unblockResponse = Invoke-RestMethod -Uri ($unblockIPsUrl+"POP?"+$selectedIP) -Method Post -Headers $headers -ContentType "application/json" -Body ($unblockPayload | ConvertTo-Json)

            if ($unblockResponse.success) {
                Write-Host "IP $selectedIP successfully unblocked."

Reply to Thread