AnsweredAssumed Answered

perl Akamai::Edgegrid and Traffic Management

Question asked by Ronald Tidd on Apr 26, 2016
Latest reply on Apr 29, 2016 by Kirsten Hunter

I followed the api-kickstart example for perl, successfully added in the proxy gateway and can use the get method to retreive properties

from $baseurl/config-gtm/v1/domains/MYDOMAIN.akadns.net/properties/MYPROPNAME

 

I am however having an issue trying to change the weights in my weighted round robin setup via PUT however.

 

here is my simple function

=======================================================

sub adjustWeights

{

     my $config_file = "/OUR/CONNECTION/DATA/FILE";

     my $section = "default";

     my $ua = new Akamai::Edgegrid(

          config_file=>$config_file,

          section=>$section,

          debug= 0);

     my $baseurl = "https://" . $ua->{host};

     my $jsonData=

     '{

          "trafficTargets": [

               {

                    "datacenterId" : 3135,

                    "enabled" true,

                    "weight" : 50

               },

               {

                    "datacenterId" : 3135,

                    "enabled" true,

                    "weight" : 50

               }

          ]

     }';

     my $data = decode_json($jsonData);

 

     $ua->proxy(["https"], "http://MY.COMPANY.PROXY:PORT/");

     my $response = $ua->put("$baseurl/config-gtm/v1/domains/MYDOMAIN.akadns.net/properties/MYPROPNAME", "Content-Type"=>"application/json", Content=>$data);

 

     my $json=JSON->new

     print $json->pretty->encode($json->decode($response->content)):

}

===============================================================

OUTPUT from running this funciton :

{

     "title" : "Bad Request",

     "detail" : "Could not read JSON: parse exception: 'Unrecognized token 'trafficTargets' : was expecting 'null', 'true', 'false or NaN'",

     "status" : 400,

     "type" : "https://problems.luna.akamaiapis.net/config-gtm/v1/malformedRequestEntity"

}

 

I tried adding in the required properties for handoutMode, name, scoreAggregationType, and type, but it still fails on one of the properties with an unrecognized token.

 

I've gone so far as to replace the entire jsonData structure with everything I get back from my get request that works, but it still fails with an unrecognized token on one of the properties. 

 

Besides the obvious of using perl... what am I doing wrong here?

Outcomes