1

hi i have this data and i want to change something in it that i want to change using PHP the problem is i don't know how to access that specific data it is stored in a variable ill post my code below also i have labeled the data i want to change.

{
  "id" : "",
  "name" : "",
  "namePostfix" : "",
  "updatedTime" : "2016-11-29T16:35:31.189Z",
  "createdTime" : "2016-11-07T05:19:20.352Z",
  "clientId" : "",
  "url" : "",
  "impressionUrl" : "",
  "trafficSource" : {
    "id" : "",
    "name" : "",
    "postbackUrl" : null,
    "pixelRedirectUrl" : null,
    "type" : "CUSTOM",
    "predefinedType" : null
  },
  "country" : {
    "code" : "NZ",
    "name" : "New Zealand"
  },
  "costModel" : "CPA",
  "clickRedirectType" : "DOUBLE_HTML",
  "paths" : [ {
    "weight" : 100,
    "active" : true,
    "landers" : [ {
      "lander" : {
        "id" : "",
        "namePostfix" : "",
        "name" : ""
      },
      "weight" : 100
    } ],
    "offers" : [ {
      "offer" : {
        "id" : "",
        "name" : "",
        "namePostfix" : ""
      },
      "weight" : 100
    } ]
  } ],
  "pathsGroups" : [ {
    "condition" : {
      "country" : {
        "predicate" : "MUST_BE",
        "countryCodes" : [ "NZ" ]
      },
      "customVariableConditions" : [ {
        "predicate" : "MUST_NOT_BE",
        "index" : 0,
        "texts" : [ "[zone]", "Unknown", "unknown" ],
        "text" : "[zone]"
      }, null, {
        "predicate" : "MUST_NOT_BE",
        "index" : 2,
        "texts" : [ "Unknown", "[clickid]", "unknown" ],
        "text" : "Unknown"
      }, null, null, null, null, null, null, null ]
    },
    "paths" : [ {
      "weight" : 100,
      "active" : true,
      "landers" : [ {
        "lander" : {
          "id" : "",
          "namePostfix" : "",
          "name" : ""
        },
        "weight" : 100
      }, {
        "lander" : {
          "id" : "",
          "namePostfix" : "",
          "name" : ""
        },
        "weight" : 100
      } ],
      "offers" : [ {
        "offer" : {
          "id" : "",
          "name" : "",
          "namePostfix" : ""
        },
        "weight" : 100
      } ]
    } ],
    "active" : false //change this to true
  } ],
  "cpa" : 1.2,
  "revenueModel" : "RPA_AUTO",
  "redirectTarget" : "INLINE",
  "inlineFlow" : {
    "name" : "",
    "countries" : [ {
      "code" : "",
      "name" : ""
    } ],
    "conditionalPathsGroups" : [ {
      "conditions" : {
        "country" : {
          "predicate" : "MUST_BE",
          "countries" : [ {
            "code" : "",
            "name" : ""
          } ]
        },
        "customVariable" : {
          "values" : [ {
            "predicate" : "",
            "variableIndex" : 1,
            "variableValues" : 
          }, {
            "predicate" : "MUST_NOT_BE",
            "variableIndex" : 3,
            "variableValues" : 
          } ]
        }
      },
      "paths" : [ {
        "name" : "Path 1",
        "active" : true,
        "weight" : 100,
        "landers" : [ {
          "weight" : 100,
          "lander" : {
            "id" : "",
            "name" : "",
            "numberOfOffers" : 1,
            "url" : ""
          }
        }, {
          "weight" : 100,
          "lander" : {
            "id" : "",
            "name" : "",
            "numberOfOffers" : 1,
            "url" : ""
          }
        } ],
        "offers" : [ {
          "weight" : 100,
          "offer" : {
            "id" : "",
            "name" : "",
            "url" : "",
            "affiliateNetwork" : {
              "id" : ""
            }
          }
        } ],
        "offerRedirectMode" : "DOUBLE_HTML",
        "realtimeRoutingApiState" : "DISABLED"
      } ]
    } ],
    "defaultPaths" : [ {
      "name" : "Path 1",
      "active" : true,
      "weight" : 100,
      "landers" : [ {
        "weight" : 100,
        "lander" : {
          "id" : "",
          "name" : "",
          "numberOfOffers" : 1,
          "url" : ""
        }
      } ],
      "offers" : [ {
        "weight" : 100,
        "offer" : {
          "id" : "",
          "name" : "",
          "url" : "",
          "affiliateNetwork" : {
            "id" : ""
          }
        }
      } ],
      "offerRedirectMode" : "DOUBLE_HTML",
      "realtimeRoutingApiState" : "DISABLED"
    } ],
    "defaultOfferRedirectMode" : "DOUBLE_HTML"
  }
}

here is my code:

$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>";
            echo '<pre>' . print_r($resulta, true) . '</pre>';
            $resulta->pathGroups->active='true';

i really dont know if what iam doing is right. someone help me please tried using json_decode here is my code where i use json_decode:

$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']=1;

yes i have change the value with this code but my problem is how will i put the value back to the $resulta variable i need all the data in one piece before i can submit to server.

3
  • 1
    Have you tried json_decode() ? Commented Nov 30, 2016 at 9:17
  • what error does that give you? also, remove the quote braces around true. Commented Nov 30, 2016 at 9:21
  • it doesn't give any error, ill update my post and add the part where i use json_decode give me sec Commented Nov 30, 2016 at 9:24

2 Answers 2

1

Try this...

$arr = json_decode($json);
$arr->pathsGroups[0]->active = 'true';
Sign up to request clarification or add additional context in comments.

Comments

0

Use json_decode() like:

$arr = json_decode($json, true);   // 2 parameter is true so that it returns an array instead of object

it will convert the json data into array and use it accordingly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.