New Developer - Unsure how to Integrate API

So I’ve decided to work with fetch. I’ve written some code and I’ve run into the same issue I explained earlier - most examples I’ve found are with the old API. Quite literally every single example I’ve found under the new API no longer works…

Here’s what I’ve got so far (converted to pseudocode obviously), please let me know if this is the correct place to post this code or if I need to open a new thread elsewhere: https://pastebin.com/S8grYWJa