« Général:FAQ API Select » : différence entre les versions
| (Une version intermédiaire par un autre utilisateur non affichée) | |||
| Ligne 33 : | Ligne 33 : | ||
J'appelle donc : https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/bc1ccb9cdc51f0d131cf6a7a8d6a72c4/growth/DetailMonth.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f&Instance=AORACH&NbMonth=12<br/> | J'appelle donc : https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/bc1ccb9cdc51f0d131cf6a7a8d6a72c4/growth/DetailMonth.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f&Instance=AORACH&NbMonth=12<br/> | ||
<br/> | <br/> | ||
===PHP=== | ===PHP=== | ||
Vous pouvez venir récupérer les données avec en PHP, par exemple : | |||
<br> | |||
<syntaxhighlight lang="php" line> | <syntaxhighlight lang="php" line> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html> | <html> | ||
<meta charset="utf-8"/> | <meta charset="utf-8"/> | ||
<head> | <head> | ||
<title>dbSQWare API Viewer</title> | |||
<style> | |||
thead, tfoot { | |||
background-color: #3f87a6; | |||
color: white; | |||
} | |||
tbody { | |||
background-color: #e4f0f5; | |||
} | |||
table { | |||
border-collapse: collapse; | |||
border: 2px solid grey; | |||
} | |||
td, th { | |||
border: 1px solid grey; | |||
padding: 5px 10px; | |||
} | |||
td { | |||
text-align: center; | |||
} | |||
</style> | |||
</head> | </head> | ||
<body> | <body> | ||
| Ligne 77 : | Ligne 75 : | ||
/** | /** | ||
* | * Does API request. | ||
* | * | ||
* @param | * @param string $method : Request method | ||
* @param | * @param string $url : Website url | ||
* @param | * @param array $headers : JSON object headers | ||
* @param | * @param string $data : JSON object data | ||
* @return | * @return string | ||
*/ | */ | ||
function | function apiRequest(string $method, string $url, array $headers = [], $data = '{}'): string | ||
{ | |||
$curl = curl_init(); | |||
curl_setopt_array($curl, [ | |||
CURLOPT_URL => $url, | |||
CURLOPT_RETURNTRANSFER => true, | |||
CURLOPT_ENCODING => '', | |||
CURLOPT_MAXREDIRS => 10, | |||
CURLOPT_TIMEOUT => 0, | |||
CURLOPT_FOLLOWLOCATION => true, | |||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |||
CURLOPT_SSL_VERIFYHOST => 0, | |||
CURLOPT_SSL_VERIFYPEER => 0, | |||
CURLOPT_CUSTOMREQUEST => $method, | |||
CURLOPT_POSTFIELDS => $data, | |||
CURLOPT_HTTPHEADER => $headers, | |||
]); | |||
$response = curl_exec($curl); | |||
curl_close($curl); | |||
return $response; | |||
} | } | ||
/** | /** | ||
* | * Get backup traces. | ||
* | * | ||
* @return array | |||
* @return | */ | ||
*/ | function getBackupTraces(): array | ||
function | { | ||
// Init request | |||
$method = 'GET'; | |||
$url = "https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/c52bd74cbffb0ec0bdee4a6c41231c85/backups/LackBackupsJustified.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f"; | |||
// API request | |||
$response = apiRequest($method, $url); | |||
if (empty($response) || $response == 'Url Failure') { | |||
echo('Failure of the API request !'); | |||
return []; | |||
} | |||
$response = json_decode($response, true); | |||
return $response; | |||
} | } | ||
function main(){ | function main(): void | ||
{ | |||
// Get backup traces | |||
$response = getBackupTraces(); | |||
$print = "<table>"; | |||
$loop = 0; | |||
foreach ($response as $key => $json) { | |||
if ($loop == 0) { | |||
$print .= "<thead><tr>"; | |||
foreach ($json as $key => $value) { | |||
$print .= "<th>{$key}</th>"; | |||
} | |||
$print .= "</tr></thead>"; | |||
} | |||
$print .= "<tr>"; | |||
foreach ($json as $key => $value) { | |||
$print .= "<td>{$value}</td>"; | |||
} | |||
$print .= "</tr>"; | |||
$loop++; | |||
} | |||
$print .= "</table>"; | |||
echo($print); | |||
} | } | ||
| Ligne 158 : | Ligne 166 : | ||
</html> | </html> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Dernière version du 25 juin 2025 à 14:04
Généralités
Limites de cette section
Cette section n’a pas la prétention de traiter tous les cas possibles d'utilisation de l'API de récupération des données.
Vous pouvez récupérer toutes les données présentées dans des tableaux de l'interface graphique, soit pas loin de 2000 API.
Si vous possédez des "tableaux customs", ils sont également requêtables par cette technique.
Attention, les URL sont encodées, il faut donc aller récupérer dans la console graphique la correspondance de l'URL dont on veut récupérer les données !
Vous devez être à l'aise avec le concept des API, si ce n'est pas le cas, faites appel au support.
Paramétrage préalable
Afin de pouvoir utiliser l'API de récupération des données, vous devez au préalable avoir paramétré un login avec le type d'authentification "internal_api".
Par défaut, vous devez avoir le login "api_viewer" qui a été créé avec le type d'authentification "internal_api".
Vous pouvez bien évidemment créer un autre compte, changer son mdp, changer son nom ..., le tout sera de s'adapter par rapport à l'exemple !
Exemples d'utilisation
Vous devez adapter les exemples suivants avec vos propres données (URL, user, password, ...)
Ceci représente une base pour du Python, PHP et shell.
Vous pouvez bien évidemment utiliser le langage de votre choix.
Dans cet exemple, nous avons voulu afficher les données de https://webdba.dbsqware.com/oracle/all/backups/LackBackupsJustified.html ...
On va donc dans le menu "Management" (soit du sgbd qui nous intéresse, soit de "All") puis dans "ApiList ou ListeApi".
Là, on trouve le tableau des correspondances URL "en clair" et URL "encodées".
On prend "oracle/all/backups/LackBackupsJustified" et on le met dans le filtre de la colonne "Clear_url".
Cela nous donne /032ef131dbb9ef74f2445fa5aba80942/c52bd74cbffb0ec0bdee4a6c41231c85/backups/LackBackupsJustified.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f.
On peut donc tenter l'appel direct dans un navigateur pour voir si cela nous sort les données avec l'URL suivante:
https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/c52bd74cbffb0ec0bdee4a6c41231c85/backups/LackBackupsJustified.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f
Attention, si l'URL de départ comporte des paramètres, ne pas oublier de la rajouter !
Exemple avec : https://webdba.dbsqware.com/oracle/unit/growth/DetailMonth.html?Instance=AORACH&NbMonth=12
Je filtre sur : oracle/unit/growth/DetailMonth
Cela donne : /032ef131dbb9ef74f2445fa5aba80942/bc1ccb9cdc51f0d131cf6a7a8d6a72c4/growth/DetailMonth.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f
Il faut donc ajouter à la fin de l'URL &Instance=AORACH&NbMonth=12
J'appelle donc : https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/bc1ccb9cdc51f0d131cf6a7a8d6a72c4/growth/DetailMonth.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f&Instance=AORACH&NbMonth=12
PHP
Vous pouvez venir récupérer les données avec en PHP, par exemple :
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head>
<title>dbSQWare API Viewer</title>
<style>
thead, tfoot {
background-color: #3f87a6;
color: white;
}
tbody {
background-color: #e4f0f5;
}
table {
border-collapse: collapse;
border: 2px solid grey;
}
td, th {
border: 1px solid grey;
padding: 5px 10px;
}
td {
text-align: center;
}
</style>
</head>
<body>
<h1>dbSQWare API Viewer</h1>
<?php
/**
* Does API request.
*
* @param string $method : Request method
* @param string $url : Website url
* @param array $headers : JSON object headers
* @param string $data : JSON object data
* @return string
*/
function apiRequest(string $method, string $url, array $headers = [], $data = '{}'): string
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $headers,
]);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
/**
* Get backup traces.
*
* @return array
*/
function getBackupTraces(): array
{
// Init request
$method = 'GET';
$url = "https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/c52bd74cbffb0ec0bdee4a6c41231c85/backups/LackBackupsJustified.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f";
// API request
$response = apiRequest($method, $url);
if (empty($response) || $response == 'Url Failure') {
echo('Failure of the API request !');
return [];
}
$response = json_decode($response, true);
return $response;
}
function main(): void
{
// Get backup traces
$response = getBackupTraces();
$print = "<table>";
$loop = 0;
foreach ($response as $key => $json) {
if ($loop == 0) {
$print .= "<thead><tr>";
foreach ($json as $key => $value) {
$print .= "<th>{$key}</th>";
}
$print .= "</tr></thead>";
}
$print .= "<tr>";
foreach ($json as $key => $value) {
$print .= "<td>{$value}</td>";
}
$print .= "</tr>";
$loop++;
}
$print .= "</table>";
echo($print);
}
main();
?>
</body>
</html>