« Module:ZoteroAPI » : différence entre les versions

Page créée avec « local p = {} function p.getItemRawJson(frame) local itemKey = frame.args[1] if not itemKey or itemKey == '' then return '❌ Aucun itemKey fourni.' end local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json' local data = mw.ext.externalData.getExternalData({ url = url, format = 'json' }) if not data or next(data) == nil then return '❌ Aucune donnée reç... »
 
Aucun résumé des modifications
Ligne 9 : Ligne 9 :
     local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json'
     local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json'


     local data = mw.ext.externalData.getExternalData({
     local jsonString = mw.ext.externalData.getExternalData({
         url = url,
         url = url,
         format = 'json'
         format = 'json'
     })
     })


     if not data or next(data) == nil then
     if not jsonString or jsonString == '' then
         return '❌ Aucune donnée reçue de Zotero.'
         return '❌ Aucune donnée reçue de Zotero.'
     end
     end


    -- Encode le tableau en JSON lisible si possible
     return '<pre>' .. jsonString .. '</pre>'
    local ok, json = pcall(mw.text.jsonEncode, data)
    if not ok then
        return '❌ Erreur d’encodage JSON.'
    end
 
     return '<pre>' .. json .. '</pre>'
end
end


return p
return p