Module:ZoteroItem

De alcolois
Aller à la navigation Aller à la recherche

La documentation pour ce module peut être créée à Module:ZoteroItem/doc

local p = {}

function p.getItem(frame)
    local key = frame.args[1]
    if not key or key == "" then
        return "Erreur : aucun itemKey fourni"
    end

    local groupId = "4893620"
    local url = string.format(
        "https://api.zotero.org/groups/%s/items/%s?format=json&include=data",
        mw.uri.encode(groupId),
        mw.uri.encode(key)
    )

    local t, errs = mw.ext.externalData.getWebData{
        url = url,
        format = "JSON"
    }

    -- 🔍 Diagnostic détaillé
    if errs then
        return "DEBUG: erreurs rencontrées : " .. table.concat(errs, "; ")
    elseif t == nil then
        return "DEBUG: t est nil — la requête n’a rien retourné"
    elseif type(t) == "string" then
        return "DEBUG: t est une chaîne ! Contenu brut = " .. mw.text.escape(t)
    elseif not t.__json then
        return "DEBUG: t est une table, mais sans champ '__json'. Contenu brut = " .. mw.text.jsonEncode(t)
    else
        return "DEBUG: succès ! Contenu de __json = " .. mw.text.jsonEncode(t.__json)
    end
end

return p