Aller au contenu

Messages recommandés

Posté(e)

bonjour,

 

Si quelqu'un pouvait m'aiguiller sur de la requête api car je sèche un peu malgré mes lectures sur le forum.

Je cherche à récupérer des info sur les backup de la HC3. je fais tourner cette fonction qui les remonte bien mais je ne vois pas comment récupérer uniquement celles qui m'interesse (exemple date du dernier backup en remote ou en local).

Voici le code :

function QuickApp:test()
self.http:request("http://127.0.0.1/api/service/backups", {
        options = {
            data = json.encode(requestBody),
            method = "GET",
            headers = {
                ["Content-Type"] = "application/json",
                ["Accept"] = "application/json",
                 -- Header with basic auth containing admin:admin. Replace it with your crendentials. 
                ["Authorization"] = "Basic  XXXXXXXXXXXXXXXX", -- mot de passe en base 64
            }
        },
        success = function(response)
            self:debug(response.status)
            self:debug(response.data)
        end,
        error = function(message)
            self:debug("error:", message)
        end
    })
end

J'obtiens bien en retour le résultat suivant mais comment l'exploiter ? 

 

[{"type":"local","localBackupPath":"\/backups\/","uploadedBackup":[{"id":"1652551813","timestamp":1652551813,"compatible":true,"automatic":false,"devices":3,"rooms":19,"scenes":7,"description":"Mon_Backup","softVersion":"5.110.15","filename":"backup_HC3-00020112_2022_05_14-20_10_13.fbi","size":"725.5K","slavesBackups":[],"zwaveEngineVersion":"2.0"},{"id":"1657358062","timestamp":1657358062,"compatible":true,"automatic":false,"devices":4,"rooms":19,"scenes":10,"description":"Mon_Backup","softVersion":"5.111.48","filename":"backup_HC3-00020112_2022_07_09-11_14_23.fbi","size":"901.3K","slavesBackups":[],"zwaveEngineVersion":"2.0"}],"automaticCount":0,"automaticLimit":3,"manualCount":2,"manualLimit":3},{"totalSpace":"50.0M","usedSpace":"2.0M","usedSpacePercentage":"4%","type":"remote","backups":[{"id":"2057741","timestamp":1651168384,"compatible":true,"automatic":false,"devices":2,"rooms":19,"scenes":3,"description":"autobackup","softVersion":"5.110.15","zwaveEngineVersion":"2.0","filename":"backup_2022_04_28-19_53_04.7z","size":"489.3K"},{"id":"2121584","timestamp":1654450039,"compatible":true,"automatic":true,"devices":4,"rooms":19,"scenes":7,"description":"Auto backup 5.110.15","softVersion":"5.110.15","zwaveEngineVersion":"2.0","filename":"backup_2022_06_05-19_27_19.7z","size":"582.3K"},{"id":"2153547","timestamp":1657358824,"compatible":true,"automatic":false,"devices":4,"rooms":19,"scenes":10,"description":"Mon_Backup","softVersion":"5.111.48","zwaveEngineVersion":"2.0","filename":"backup_2022_07_09-11_27_04.7z","size":"932.6K"}]}]

 

Par avance merci aux champions qui passeraient par là.

Posté(e)

dans ta fonction success, tu dois décoder puis analyser la reponse qui est sous forme de json:

local resp = json.decode(response.data)
local type = resp[1].type

 

  • Like 1
×
×
  • Créer...