Général:FAQ API Select : Différence entre versions

De WikiFr_dbSQWare
Aller à : navigation, rechercher
(PHP)
(PHP)
Ligne 115 : Ligne 115 :
 
             <nowiki>$t_print .= "<thead><tr>";</nowiki>
 
             <nowiki>$t_print .= "<thead><tr>";</nowiki>
 
             foreach($json as $key => $value){
 
             foreach($json as $key => $value){
                 $t_print .= "<th>$key</th>";
+
                 <nowiki>$t_print .= "<th>$key</th>";</nowiki>
 
             }
 
             }
 
             <nowiki>$t_print .= "</tr></thead>";</nowiki>
 
             <nowiki>$t_print .= "</tr></thead>";</nowiki>
Ligne 122 : Ligne 122 :
 
         <nowiki>$t_print .= "<tr>";</nowiki>
 
         <nowiki>$t_print .= "<tr>";</nowiki>
 
         foreach($json as $key => $value){
 
         foreach($json as $key => $value){
             $t_print .= "<td>$value</td>";
+
             <nowiki>$t_print .= "<td>$value</td>";</nowiki>
 
         }
 
         }
 
         <nowiki>$t_print .= "</tr>";</nowiki>
 
         <nowiki>$t_print .= "</tr>";</nowiki>

Version du 25 mai 2023 à 12:14

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 plus de 1500 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 .

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.

Python

// A venir

PHP

<!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

/**
 * f_api_request does API request
 * 
 * @param String $v_method : request method
 * @param String $v_url    : website url
 * @param Array $t_headers : JSON object headers 
 * @param Array $t_data    : JSON object data
 * @return $v_response     : API request return
 */
function f_api_request($v_method, $v_url, $t_headers=[], $t_data='{}'){
    $v_curl = curl_init();

    curl_setopt_array($v_curl, array(
        CURLOPT_URL            => $v_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  => $v_method,
        CURLOPT_POSTFIELDS     => $t_data,
        CURLOPT_HTTPHEADER     => $t_headers,
    ));

    $v_response = curl_exec($v_curl);
    curl_close($v_curl);
    return $v_response;
}

/**
 * f_get_backup_trace get backup traces
 * 
 * @param Array $t_data  : JSON object data
 * @return Array mixed[] : request response
 */
function f_get_backup_trace(){
    $v_method  = "GET";
    $v_url     = "https://webdba.dbsqware.com/032ef131dbb9ef74f2445fa5aba80942/c52bd74cbffb0ec0bdee4a6c41231c85/backups/LackBackupsJustified.apiOut?user=api_viewer&password=78739d04e87fb581416908b7547cccd0abf1b17f";

    $v_response = f_api_request($v_method, $v_url); // API request
    return $v_response;
}

function main(){
    // Get backup traces
    $v_json_response = json_decode(f_get_backup_trace(), true);

    $t_print = "<table>";

    $v_loop = 0;
    foreach($v_json_response as $key => $json){
        if($v_loop == 0){
            $t_print .= "<thead><tr>";
            foreach($json as $key => $value){
                $t_print .= "<th>$key</th>";
            }
            $t_print .= "</tr></thead>";
        }

        $t_print .= "<tr>";
        foreach($json as $key => $value){
            $t_print .= "<td>$value</td>";
        }
        $t_print .= "</tr>";
        $v_loop++;
    }

    $t_print .= "</table>";
    echo($t_print);
}

main();

?>

</body>
</html>

Shell

#!/bin/sh
## A venir