Hm then im not sure, it seems like one of the variables isnt returning something, idk what exactly has to be filled in tho.
is there a reason you first do system.util.jsonEncode() and then an other encode() ?
Did you check out Publish to topics using system.cirruslink.engine.publish() - #2 by pturmel ?