New Dev: Request for httpPost Groovy Examples

The "top level" variable not working is a Groovy thing: it ultimately becomes Java-esque, so all top-level code gets shoved into a method behind the scenes (because that's how Java needs things to be), and like any variable declared inside a method, is not accessible from elsewhere. Groovy's @Field annotation solves this by "elevating" these variables to class fields. So, this should solve that prolem:

@Field String apiURL = "https://api.particle.io/v1/devices/"

(Yeah, I also specified the type...might as well if you know.) However, this value will be re-initialized to the above on each execution of the driver. You'll often see this instead:

@Field static String apiURL = "https://api.particle.io/v1/devices/"

...which only initializes the value when the driver code is saved/updated, with a new concern being that the value is shared (static) among all device instances that use this driver. In your case, this seems unlikely to be a problem (but something to keep in mind if you're using these to store data, meaning they may be modified by one instance of a driver--for all instances). I also like to make these final, but I have no idea from Hubitat's (lack of) documentation if that makes a difference in this case.

As for why the POST isn't working, I'm not sure. But I don't actually see an error in the logs you pasted: resp would indeed be an AsyncResponse object, and the (optional) data parameter was not provided, so it's null as expected. This post probably has more documentation on the AsyncResponse object than the actual docs and might be a good starting point for using it to figure out if something went wrong:

(I'm mostly familiar with the Hue Bridge here, which returns JSON, so resp.getJSON() is often what I use to see if the Bridge threw a fit or of things worked, but your API is probably different.)