There are a lot of Invoke-RestMethod commands in these steps, could you break and narrow down to which invoke command is failing? That would make it easier to figure out and fix.
Thanks!