Error message when uploading a ticket attachment via custom function | Deluge | Workflow

Error message when uploading a ticket attachment via custom function | Deluge | Workflow

Hello there,

I would like to have the email attachments moved to the separate attachment section of the ticket when sending an email from a ticket or when receiving a customer email. For this I have created a custom function as seen below. This also works in most cases, but sometimes it fails for unknown reasons. And not robustly reproducible either, I can't see any regularity or dependency on any circumstances.

The last example what puzzles me is an email 10 .xlsx attachments, all files were between 10 - 30 KB in size. The function had managed to process 8 of them correctly. The missing ones were not the largest files of these 10 pieces, nor did they resemble each other in any way so that conclusions could be drawn.

Error message:

{"errorCode":"INVALID_DATA","message":"The data is invalid due to validation restrictions","errors":[{"fieldName":"/file","errorType":"missing","errorMessage":""}]},{"errorCode":"INVALID_DATA","message":"The data is invalid due to validation restrictions","errors":[{"fieldName":"/file","errorType":"missing","errorMessage":""}]}

The stupid thing is also, after I received the error, I ran the function again manually and lo and behold - no problem occurred. The function is triggered on ticket creation and customer response via workflow. Only then there are errors from time to time.

Custom function:

// Standardwerte
orgId = "<anynonymized>";
errors = List();
try
{
    // ###############################################################################################################################################################
    // get latest thread
    // ###############################################################################################################################################################
    getTicketThread = invokeurl
    [
        url :"https://desk.zoho.eu/api/v1/tickets/" + ticketID + "/latestThread"
        type :GET
        connection:"<anynonymized>"
    ];
    // Prefix for filename
    dir = getTicketThread.get("direction");
    if(dir == "in")
    {
        prefix = "Customer - ";
    }
    else
    {
        prefix = "Agent - ";
    }
    // All attachments are listed inside attachments (id, name, size, href, previewurl)
    attachmentList = getTicketThread.get("attachments");
    // ###############################################################################################################################################################
    // iterate trough all list items
    // ###############################################################################################################################################################
    for each  attachment in attachmentList
    {
        filename = prefix + attachment.get("name");
        // download file
        getAttachment = invokeurl
        [
            url :attachment.get("href")
            type :GET
            connection:"<anynonymized>"
            response-format:FILE
        ];
        // upload file as a ticket attachment
        if(getAttachment != null)
        {
            param = Map();
            getAttachment.setParamName("file");
            param.put(filename,getAttachment);
            uploadResponse = invokeurl
            [
                url :"https://desk.zoho.eu/api/v1/tickets/" + ticketID + "/attachments"
                type :POST
                parameters:param
                connection:"<anynonymized>"
            ];
            if(uploadResponse.get("id").isNull())
            {
                errors.add(uploadResponse);
            }
        }
    }
}
catch (e)
{
    errors.add(e);
}
// ###############################################################################################################################################################
// Send errors to admin mail address
// ###############################################################################################################################################################
if(errors.size() > 0)
{
    sendmail
    [
        from :zoho.adminuserid
        to :"<anynonymized>"
        subject :"<anynonymized>"
        message :errors
}


    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

                          Writer is a powerful online word processor, designed for collaborative work.

                            Zoho CRM コンテンツ




                              ご検討中の方