AnsweredAssumed Answered

Client error: 400 - CCU Purge API

Question asked by Alberto Sousa on Jun 21, 2016
Latest reply on Jun 27, 2016 by Alberto Sousa

Hi,

I would like to know all reasons to get "Client error: 400" using CCU Purge API.

 

 

In following web page I got this information: "400 - Bad request - Often a malformed purge request JSON".

https://developer.akamai.com/api/purge/ccu/reference.html

 

 

I am using the PHP example script, that works fine at my local machine.

But exactly the same script returns "Client error: 400" in my QA server.

The json parameter is the same. So I believe that maybe could be some difference at server configs.

 

 

 

$client = new Akamai\Open\EdgeGrid\Client([

  'base_uri' => $base_uri

  ]);

 

 

  $client->setAuth($client_token, $client_secret, $access_token);

 

  try {

 

 

  $purge_body ='{

   "objects": [

  "'.$url.'"

   ],

   "action": "invalidate",

   "type": "arl",

   "domain": "'.$domainAkamai.'"

  }';

 

 

 

  $response = $client->post('/ccu/v2/queues/default', [

  'body' => $purge_body,

  'headers' => ['Content-Type' => 'application/json']

  ]);

 

 

  $result= $response->getBody();

 

  } catch (\Exception $e) {

  $result=$e->getMessage();

  } 

 

 

 

 

 

I tried to use the other format example. But I got the same result (in my local server it works very well, but in QA server I got "Client error: 400"):

 

 

namespace Akamai\Open\Example;

 

 

require_once __DIR__ . '/cli/init.php';

 

 

class CcuClient

{

  /**

  * @var \Akamai\Open\EdgeGrid\Client

  */

  protected $client;

 

 

  public function __construct()

  {

  $this->client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile('ccu');

  }

 

 

  public function getQueue()

  {

  $response = $this->client->get('/ccu/v2/queues/default');

  printf("The queue currently has %s items in it\n", json_decode($response->getBody())->queueLength);

  }

 

 

  public function checkProgress($resource)

  {

  $response = $this->client->get($resource);

  return json_decode($response->getBody());

  }

 

 

  public function postPurgeRequest()

  {

  $purge_body = [

  "objects" => [

  "https://mysiteurl.com"

  ]

  ];

 

 

  printf("Adding %s to queue\n", json_encode($purge_body, JSON_UNESCAPED_SLASHES));

  $response = $this->client->post('/ccu/v2/queues/default', [

  'body' => json_encode($purge_body),

  'headers' => ['Content-Type' => 'application/json']

  ]);

  return $response;

  }

}

 

 

$ccu = new CcuClient();

 

 

try {

  $ccu->getQueue();

  $purge = $ccu->postPurgeRequest();

  $progress = $ccu->checkProgress(json_decode($purge->getBody())->progressUri);

 

 

  $seconds_to_wait = $progress->pingAfterSeconds;

  printf("You should wait %s seconds before checking queue again...\n", $seconds_to_wait);

} catch (\GuzzleHttp\Exception\ClientException $e) {

  // Handle errors

  echo "An error occurred: " .$e->getMessage(). "\n";

  echo "Please try again with --debug or --verbose flags.\n";

}

 

 

 

 

Please, someone know all the reasons that could show this error and what could I check in my QA server?

 

 

Thanks for attention.

Outcomes