You can ping any of our Admin API endpoints and see if you get a positive response. In using Cloudinary's PHP SDK, we will use its base HTTP client to perform a ping to an endpoint. Optionally, we will use Symfony's Dotenv to parse the cloud credentials such as API key and API secret that are stored in a .env file.
In composer.json, set the following dependencies:
"require": {
"cloudinary/cloudinary_php": "^2.10",
"symfony/dotenv": "^6.2"
}
Example .env file:
cloud_name=<cloudNameHere>
api_key=<apiKeyHere>
api_secret=<apiSecretHere>
Let's declare the autoload and namespaces that are needed to be included in the script:
<?php
require 'vendor/autoload.php';
use Symfony\Component\Dotenv\Dotenv;
use Cloudinary\Configuration\Configuration;
use Cloudinary\Api\ApiClient;
Set the array to contain the configuration details of the Cloudinary Account:
$cld_env = [
'cloud' => [
'cloud_name' => $_ENV['cloud_name'],
'api_key' => $_ENV['api_key'],
'api_secret' => $_ENV['api_secret']
],
'url' => [
'secure' => true
]
];
Instantiate the Configuration object and pass the configuration parameter:
$config = (new Configuration($cld_env));
$client = (new ApiClient($config));
//get the config details that was set in the ApiClient
$cloud = $client->getCloud();
$cloud_name = $cloud->cloudName;
$key = $cloud->apiKey;
$secret =$cloud->apiSecret;
Set the ping URL and ping the endpoint:
$ping_url = sprintf('https://%s:%s@api.cloudinary.com/v1_1/%s/ping', $key, $secret, $cloud_name);
$result = $client->httpClient->get($ping_url);
Echo the result status:
echo $result->getHeader('Status')[0], PHP_EOL;
The above should echo:
200 OK
Or alternatively, iterate over the response headers:
foreach($result->getHeaders() as $name => $values){
echo $name . ": " . implode(", ", $values) . "\r\n";
}
Comments
2 comments
hi Itay,
thanks. Now I get a "status: OK" message. But when I want to list my pictures filtered by tags, I get an HTML output.
What do I wrong? Using Postman and tryed to do with using the documantation on the API.
Any suggestions?
Regards, Gerhard
Hi,
Please see this:
https://support.cloudinary.com/hc/en-us/articles/203189031-How-to-retrieve-a-list-of-all-resources-sharing-the-same-tag-
Please let me know if it works for you.
Best,
Yakir
Please sign in to leave a comment.