Message API undefined method `each' for nil:NilClass (NoMethodError)

Discussion in 'ActionScripts' started by Gary Schultz, Jan 8, 2025.

Tags:
  1. Gary Schultz

    Gary Schultz New Member

    Joined:
    Nov 7, 2023
    Messages:
    18
    Likes Received:
    2
    Previously I've followed the example at https://docs.liquidfiles.com/actionscripts/message_delivery.html to get files from a FileDrop using

    message_data = JSON.parse(File.read(ARGV[0])).
    message_data["message"]["attachments"].each do |attachment|

    Now I get the error

    {"message":"ActiveJob Actionscript Job Error","filedrop":"TestSite01FD","actionscript":"ActionScriptName","message_id":"SfUuBNbzh3TjxOlQpmNF3H","execution_time":"0.63s","exit_code":1,"stdout":"","stderr":"/data/domains/default/actionscripts/ActionScriptName01:15:in `<main>': undefined method `each' for nil:NilClass (NoMethodError)\n","log_level":"error"}

    From https://docs.liquidfiles.com/actionscripts/message_delivery.html when I click on Message API link I get a 404. I take it the message API has changed? Is there a good example of how this is done in the new API?

    We are running version 4.1.0 in non-production and version 4.0.15 in production.
     
    #1 Gary Schultz, Jan 8, 2025
    Last edited: Jan 8, 2025
  2. Gary Schultz

    Gary Schultz New Member

    Joined:
    Nov 7, 2023
    Messages:
    18
    Likes Received:
    2
  3. Gary Schultz

    Gary Schultz New Member

    Joined:
    Nov 7, 2023
    Messages:
    18
    Likes Received:
    2
    This is what I see in the activity log.

    "files":[{"filename":"comedy-sportz-logo.png","size":36793,"size_human":"35.9 KB","checksum":"968289ecdecca3abfd0be6975cce2b81cf395e69eb313a0cdfa757a58fdf954f","content_type":"image/png"}]

    Which differs from the example given in the API documentation.

    "attachments":[ { "id":"Ok24eOJA1LuaQHFzNV4GMl", "filename":"01-12345 our drawings1of2.pdf", "size":10782517, "content_type":"application/pdf", "checksum":"2a5c809063b5831b3d73e4a294879fd056942b70b967f6ed7767c757a1f5bae2" ,"crc32":"3ad5a39c", "created_at":"2018-06-07T12:44:42.000Z", "system_file":"/data/domains/default/files/users/604/20180607_Ok24eOJA1LuaQHFzNV4GMl/01-12345_our_drawings1of2.pdf" },{ "id":"mr60K8v511Se0r3Ba9Imn7", "filename":"01-12345 our drawings2of2.pdf", "size":1837529, "content_type":"application/pdf", "checksum":"483d57c9cb71b43dc73826579a25624118f0b8f65928524ed8747ebe1dc41d5c", "crc32":"a493dc29", "created_at":"2018-06-07T12:44:45.000Z", "system_file":"/data/domains/default/files/users/604/20180607_mr60K8v511Se0r3Ba9Imn7/01-12345_our_drawings2of2.pdf" } ]
     
  4. David

    David Administrator
    Staff Member

    Joined:
    Dec 1, 2015
    Messages:
    808
    Likes Received:
    31
    Thanks for info, the List message link and the API example have been aligned for LF v4.1 appliances.
    https://docs.liquidfiles.com/actionscripts/message_delivery.html

    The changes are that the ["message"] part should be removed in the action script and it should be used the "system_file" attribute as physical path to be able copy the file i.e. to an external smb share.

    Code:
     
    ...
    message_data = JSON.parse(File.read(ARGV[0]))
    message_data["attachments"].each do |attachment|
     system_file = attachment["system_file"]
     %x{cat #{system_file} | \
       env PASSWD='#{password}' smbclient #{share} -U #{username} -d 0 -c 'put - "#{attachment['filename']}"'}
    end
    ....
    
     

Share This Page