I believe this is happening because my shop/user account on the sandbox is in an inconsistent state. I had to jump through hoops just to create receipts on the sandbox and since then I have made changes to things such as deleting shipping templates and entries, addresses, and listings that have left the shop in an inconsistent state. I.e. the shipping templates associated to listings no longer exists and addresses used to create receipts no longer exist. So now when I query for certain things (i.e. transactions), the server doesn't know what to do and is returning a 500.
Is there any way to clear all data associated with my account on the sandbox. I can't continue developing until this is resolved.
By the way, I switched back to production again and everything is working fine there. So it's only a problem with the sandbox.
The sandbox really needs a UI front end. It's almost impossible to test anything of substance on it.