For starters you need to do await tp.web.request( ... )
, as it is an asynchronous operation, and you need to give Templater the option to actually wait for the result from that request.
There could also be other errors, but hard to test since I’m not keen on re-writing stuff from an image…