Button to attach Mail Merge PDF into deal Attachments as

Button to attach Mail Merge PDF into deal Attachments as

Hello I am trying to create a button inside Zoho One Deals that will take a per made Mail Merge template and attach that template as a PDF in the attachment of that deal. This is the deluge script I got from Chat GPT and it does not work does anyone know what else I should do? Thank you ...

// Fetch the deal record
deal_id = input.deal_id;
deal_info = zoho.crm.getRecordById("Deals", deal_id);

// Generate the Mail Merge PDF (Replace 'Your_Template_Name' with the actual template name)
pdf_response = zoho.crm.generateMailMerge("Deals", deal_id.toString(), "Deal_Subform_PDF");

if(pdf_response.containsKey("document_id")) 
{
    // Attach the generated PDF to the Deal record
    attachment = {
        "Owner" : {"id": deal_info.get("Owner.id")},
        "Parent_Id" : {"id": deal_info.get("id")},
        "File_Name" : "Deal_Subform_Report.pdf",
        "Attachment" : pdf_response.get("document_url")
    };

    response = zoho.crm.createRecord("Attachments", attachment);
    return "PDF Generated and Attached Successfully!";
}
else
{
    return "Failed to Generate PDF";
}