I don't want to be misleading. I had Grok 3 try to figure this out. It's proved to be obviously beyond me. Grok 3 with a little help from me on how to write to the NPC Character sheet directly got farther than I could. But it couldn't quite complete the process despite my best effort/thoughts on what flags we were missing to clue Roll20 into the fact that our attack block was an attack block. Basically, the insertion of the attack into the NPC character sheet is not recognized as an attack in Roll20.   Despite my best efforts, I cannot figure out what the UI manipulates to flag an attack block on the NPC character sheet as a clickable attack block with a functional cog. Hence my desperate appeal to the forum. I can write in the block, but can't make it work. The red outline around my created block also seems to indicate Roll20 is quite aware I have done it incorrectly. But, with a little Grok 3 assistance, here is as far as I got. This is as far as I was able to get testing how to insert a block under actions as a melee attack into the NPC sheet from the API. I am not posting the rest of my actual script for the spell implementation as it's not relevant. Happy to share it though if someone wants it. Everything works with the token creation and chat log output in that script. It's just writing to the NPC Character sheet (specifically in the actions block, I can write to HP and AC as intended) that I am too inept to sort out.      on("chat:message", function(msg) {
    if (msg.type === "api" && msg.content.indexOf("!summonFey") === 0) {
        let args = msg.content.split(" --");
        if (args.length < 2) {
            sendChat("Summon Fey", "Error: Specify Fey type.");
            return;
        }
        let feyType = null;
        if (args[1].toLowerCase() === "fuming") feyType = "Fuming Fey";
        else if (args[1].toLowerCase() === "mirthful") feyType = "Mirthful Fey";
        else if (args[1].toLowerCase() === "tricksy") feyType = "Tricksy Fey";
        else {
            sendChat("Summon Fey", "Error: Invalid Fey type.");
            return;
        }
        let spellLevel = 3;
        if (args.length > 2 && args[2].startsWith("level")) {
            spellLevel = parseInt(args[2].split(" ")[1]) || 3;
        }
        if (spellLevel < 3 || spellLevel > 9) spellLevel = 3;
        let damageMod = 3 + spellLevel;
        let attackBonus = 6;
        if (msg.selected) {
            let token = getObj("graphic", msg.selected[0]._id);
            let charId = token.get("represents");
            if (charId) {
                let char = getObj("character", charId);
                let attrs = findObjs({ type: "attribute", characterid: charId });
                let spellAttackAttr = attrs.find(a => a.get("name") === "spell_attack_bonus");
                if (spellAttackAttr) {
                    let bonus = parseInt(spellAttackAttr.get("current"));
                    if (!isNaN(bonus)) attackBonus = bonus;
                }
            }
        }
        sendChat("Summon Fey", `Using attack bonus: +${attackBonus}`);
        let char = findObjs({ type: "character", name: feyType })[0];
        if (!char) {
            sendChat("Summon Fey", `Error: "${feyType}" not found.`);
            return;
        }
        sendChat("Summon Fey", `Found ${feyType} with ID: ${char.id}`);
        let newRowId = generateRowID();
        sendChat("Summon Fey", `Creating attack with ID: ${newRowId}`);
        try {
            createObj("attribute", {
                name: `repeating_npcaction_${newRowId}_name`,
                characterid: char.id,
                current: "Shortsword (Higher Level Cast)"
            });
            setTimeout(() => {
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_flag`,
                    characterid: char.id,
                    current: "on"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_tohit`,
                    characterid: char.id,
                    current: `${attackBonus}`
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_tohitrange`,
                    characterid: char.id,
                    current: `+${attackBonus}, Reach 5 ft.`
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_onhit`,
                    characterid: char.id,
                    current: `${damageMod + 1} (1d6+${damageMod}) Piercing damage plus 3 (1d6) force damage`
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_damage`,
                    characterid: char.id,
                    current: `1d6+${damageMod}`
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_damagetype`,
                    characterid: char.id,
                    current: "Piercing"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_damage2`,
                    characterid: char.id,
                    current: "1d6"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_damagetype2`,
                    characterid: char.id,
                    current: "force"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_range`,
                    characterid: char.id,
                    current: "5 ft."
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_target`,
                    characterid: char.id,
                    current: "One Target"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_damage_flag`,
                    characterid: char.id,
                    current: "{{damage=1}} {{dmg1flag=1}} {{dmg2flag=1}}"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_crit`,
                    characterid: char.id,
                    current: "1d6"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_attack_crit2`,
                    characterid: char.id,
                    current: "1d6"
                });
                createObj("attribute", {
                    name: `repeating_npcaction_${newRowId}_description`,
                    characterid: char.id,
                    current: "Testy MctestFace" // Exact match to Test Sword
                });
                sendChat("Summon Fey", "Attack added with Testy MctestFace description! Refresh, click cog to save if needed, then test.");
            }, 1000); // Delay to mimic UI timing
        } catch (e) {
            sendChat("Summon Fey", `Error: ${e.message}`);
        }
    }
});
function generateRowID() {
    return "-" + Math.random().toString(36).substr(2, 9);
}