0

I can display the values using GET but i don't know how to use PUT to submit a request that will change the value of my data. here is my code:

 if($visit >= 10){

                    $wh = curl_init();

                curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
                curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "GET");


                $head = array();
                $head[] = "Cwauth-Token: " . $tok;
                curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

                $resulta = curl_exec($wh);
                if (curl_errno($wh)) {
                    echo 'Error:' . curl_error($wh);
                }
                echo "Request:" . "<br>";
                $campinfo = json_decode($resulta, true);
                echo '<pre>' . print_r($campinfo, TRUE) . '</pre>';
                foreach($campinfo['pathsGroups'] as $datacamp){
                    echo $datacamp['active'];

Here is a part of my data:

Array
(
    [pathsGroups] => Array
        (
            [0] => Array
                (
                    [condition] => Array
                        (
                            [country] => Array
                                (
                                    [predicate] => MUST_BE
                                    [countryCodes] => Array
                                        (
                                            [0] => IQ
                                        )

                                )

                            [customVariableConditions] => Array
                                (
                                    [0] => Array
                                        (
                                            [predicate] => MUST_NOT_BE
                                            [index] => 0
                                            [texts] => Array
                                                (
                                                    [0] => 
                                                    [1] => Unknown
                                                    [2] => unknown
                                                )

                                            [text] => 
                                        )

                                    [1] => Array
                                        (
                                            [predicate] => MUST_NOT_BE
                                            [index] => 1
                                            [texts] => Array
                                                (
                                                    [0] => Unknown
                                                    [1] => 
                                                    [2] => unknown
                                                )

                                            [text] => Unknown
                                        )

                                    [2] => 
                                    [3] => 
                                    [4] => 
                                    [5] => 
                                    [6] => 
                                    [7] => 
                                    [8] => 
                                    [9] => 
                                )

                        )

                    [paths] => Array
                        (
                            [0] => Array
                                (
                                    [weight] => 100
                                    [active] => 1
                                    [landers] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [lander] => Array
                                                        (
                                                            [id] => 
                                                            [namePostfix] => 
                                                            [name] => Global 
                                                        )

                                                    [weight] => 100
                                                )

                                        )

                                    [offers] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [offer] => Array
                                                        (
                                                            [id] => 
                                                            [name] => 
                                                            [namePostfix] => 
                                                        )

                                                    [weight] => 100
                                                )

                                        )

                                )

                        )

                    [active] => 1 // change this to false so that it will be turned off in in the website
                )

        )



)

i want to change the active so i could turn off pathgroups

Jan Aranas
  • 67
  • 5
  • Possible duplicate of [PHP cURL HTTP PUT](http://stackoverflow.com/questions/5043525/php-curl-http-put) – smarber Nov 28 '16 at 14:34
  • I've checked PHP cURL HTTP PUT and i dont quite understand, i only know basic php. can you explain it to me ? please ive been trying to solve this for more than 12 hours now – Jan Aranas Nov 28 '16 at 15:13
  • i know how to echo active in the array but i don't know how to alter it and send it to the server. – Jan Aranas Nov 28 '16 at 15:16

1 Answers1

0

You need to make sure the url with PUT performs an UPDATE (it's a convention not an obligation). You need to know perfectly what your data looks like.

And here what that should look like (with some explanation...)

            // New values
            // This should contain all the values with the new value of the active key
            // it should start like this based on the output you provided
            // $data = array(
            //     'pathsGroups' => array(
            //           array(
            //              'condition' => ...
            //    ...etc
            // );
            $data = array(
                 // values
            );

            $wh = curl_init();

            curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
            curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
            // You use put exactly the same way as GET
            curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "PUT");
            // Here you pass your new values, with GET we don't have this
            curl_setopt($wh, CURLOPT_POSTFIELDS, http_build_query($data));

            $head = array();
            $head[] = "Cwauth-Token: " . $tok;
            curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

            $resulta = curl_exec($wh);

            if (curl_errno($wh)) {
                echo 'Error:' . curl_error($wh);
            }

            // Could help http://lornajane.net/posts/2009/putting-data-fields-with-php-curl
smarber
  • 4,829
  • 7
  • 37
  • 78