add or remove address-list mikrotik using rest API with PHP

<?php


if($_GET['action'] == 'add'){


    function setupCurl($url, $requestType, $postData = null) {

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType);

        curl_setopt($ch, CURLOPT_USERPWD, 'admin' . ':' . '123456');

        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    

        if ($postData) {

            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        }

    

        return $ch;

    }

    

    $ch = setupCurl('https://10.10.33.21:4433/rest/ip/firewall/address-list', 'PUT', '{"address": "1.2.3.4", "list": "list-pelanggan"}');

    $result = curl_exec($ch);

    

    if (curl_errno($ch)) {

        echo 'Error:' . curl_error($ch);

    }

    

    curl_close($ch);

    echo $result;

    


}


elseif($_GET['action'] == 'delete'){


    function setupCurl($url, $requestType, $postData = null) {

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType);

        curl_setopt($ch, CURLOPT_USERPWD, 'admin' . ':' . '123456');

        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    

        if ($postData) {

            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        }

    

        return $ch;

    }

    

    $ch = setupCurl('https://10.10.33.21:4433/rest/ip/firewall/address-list/print', 'POST', '{".proplist":[".id"], ".query": ["address=1.2.3.4"]}');

    $id = curl_exec($ch);

    

    if (curl_errno($ch)) {

        echo 'Error:' . curl_error($ch);

    }

    

    curl_close($ch);

    $result_array = json_decode($id, true);

    

    $chx = setupCurl('https://10.10.33.21:4433/rest/ip/firewall/address-list/'.$result_array[0]['.id'], 'DELETE');

    $result = curl_exec($chx);

    

    if (curl_errno($chx)) {

        echo 'Error:' . curl_error($chx);

    }

    

    curl_close($chx);

    echo $result;

    


}


?>