Unable to authenticate HTTP POST command to Philips Hue

Aside from the sendDeveloperReq() command listed below, does anyone know how to (or whether its even possible to) send an http POST command to the Philips Hue Hub from a ST smartapp?

private sendDeveloperReq() {
def token = app.id
def host = getBridgeIP()

sendHubCommand(new physicalgraph.device.HubAction([
	method: "POST",
	path: "/api",
	headers: [
		HOST: host
	],
	body: [devicetype: "$token-0", username: "$token-0"]], "${selectedHue}"))

}

No matter what I try, I’m getting an authentication error (even in the same app in which I have already established authentication using the 1command above and am able to run various GET and PUT commands).

An example of a failed attempt is:

private post(body) {
def token = app.id
def host = getBridgeIP()
def uri = “/api/${state.username}/scenes/”

sendHubCommand(new physicalgraph.device.HubAction([
	method: "POST",
	path: uri,
	headers: [
		HOST: host
	],
	body: body], "${selectedHue}"))   

}

I’ve also tried including devicetype: “$token-0”, username: “$token-0” within the array “body”:

  body: [devicetype: "$token-0", username: "$token-0", name: "${name}", lights: "${lights}"]], 

and formatting the body using JsonBuilder

def bodyJSON = new groovy.json.JsonBuilder(body).toString()

and then using body: bodyJSON instead.

If anyone knows how to structure an http POST command to the Philips Hue Hub (or whether its even possible), PLEASE let me know…

Thanks!!!

1 Like

This might be your problem. Hopefully it helps, Philips have changed the body slightly.

Thanks. I’ve been successful using that command for authentication only.