Changes to httpPost in release 1.1.2

While we strive to not break anything with updates, in release 1.1.2 we have made a change to httpPost that may cause an issue.

We discovered that that method was not following the same pattern that httpGet, httpPut, etc use. As such, we updated the httpPost call to follow the same pattern and that may lead to changes necessary in your code.

With this new change, you must have a try/catch around the httpPost because it will throw an exception if the response code is greater than 400. In addition you may have to add a contentType and/or requestContentType parameter if you see an issue with your call. Please let us know if you see an error that is not fixed by the above changes.

1 Like

Would you please give an example of how to use the new httpPost?

In most cases we found that no changes were necessary beyond adding the try/catch..
ie:
Before:

httpPost(params) { resp ->
     // process response
}

After:

try {
    httpPost(params) { resp ->
         // process response
    }
} catch(Exception e) {
    // log out exception
}

Here is a good example of a failure without contentType:
Before:

    def postParams = [
		uri: "http://httpbin.org/post",
		body : ["name": "value"]
	]
    
    httpPost(postParams) { resp ->
        log.debug resp.data
    }

which ends up with the error: No encoder found for request content type */*

and the new code would be:

    def postParams = [
		uri: "http://httpbin.org/post",
        contentType: "application/json",
		body : ["name": "value"]
	]
    try {
        httpPost(postParams) { resp ->
            log.debug resp.data
        }
    } catch(Exception e) {
        log.debug "error occured calling httpPost ${e}"
    }

Note the addition of the contentType in the postParams

1 Like

Thank you!

I am not sure why this isn't working.

private detect(car) {
   //Spark Core API Call
    try{
        httpPost(
			uri: "https://api.spark.io/v1/devices/${deviceId}/Read",
        	body: [access_token: token, command: car],  
            ) {resp -> 
    		def sensorValue = resp.data      
        	log.debug sensorValue.return_value
        
        	if (sensorValue.return_value > 1450 & sensorValue.return_value < 1850){
        		arrived()
        		sendEvent(name: "distance", value: "Toyota Prius V" as String, unit: "")	
            	log.debug "Annie's Car Detected" 
        	}else if (sensorValue.return_value < 2400 & sensorValue.return_value > 1100){
        		arrived()
        		sendEvent(name: "distance", value: "Honda Pilot" as String, unit: "")	
            	log.debug "Bob's Car Detected"
        	}else if (sensorValue.return_value > 2500){
        		departed()
            	sendEvent(name: "distance", value: "No Car" as String, unit: "")
            	log.debug "No Car In Parking Stall"
        	}
        } 
    }catch(Exception e){

    }
}

What is the error?
Well I guess you don't know, since you have no log line in the catch...

did you try adding the contentType?

missing content type

java.lang.IllegalArgumentException: No encoder found for request content type */* on line 64 (refresh)

I added
contentType: "application/json",

now i get this:

groovyx.net.http.HttpResponseException: Bad Request on line 64 (refresh)

try adding
requestContentType: "application/json"
as well

Still getting with the requestContentType: "application/json"

2018-08-02 08:08:13.251:debugerror occured calling httpPost groovyx.net.http.HttpResponseException: Bad Request

One more option to try, use these 2 parameters:

contentType: "application/json",
requestContentType: "application/x-www-form-urlencoded"
1 Like

Yay.. that did it :slight_smile: Thanks @chuck.schwer

It seems this recent change is also causing some issue for the Rachio Integration. I am getting this when trying to add the Rachio Integration app.

app:12312018-08-02 09:11:53.196:infoNo Rachio AuthToken Found... Please Login...

app:12312018-08-02 09:11:49.281:errorcallback exception: No encoder found for request content type /

app:12312018-08-02 09:11:42.361:infoNo Rachio AuthToken Found... Please Login...

I am seeing this error for the Amazon Echo Skill.

groovyx.net.http.HttpResponseException: Bad Request (deviceHandler)

Also seeing this for EcoBee:

HttpResponseException groovyx.net.http.HttpResponseException: Internal Server Error, 500 polling ecobee pollAttempt:1, isThermostatPolled:false, isSwitchesPolled:true, [status:[code:14, message:Authentication token has expired. Refresh your tokens. ]]

Neither of the fixes are working for me:

groovy.lang.MissingMethodException: No signature of method: com.hubitat.hub.executor.AppExecutor.error() is applicable for argument types: (java.lang.String, java.lang.IllegalArgumentException) values: [Error logging in to AT&T, java.lang.IllegalArgumentException: No encoder found for request content type /] Possible solutions: render(), getLog(), now(), iterator(), grep(), every() on line 486 (prefATTConfirm)

Here is my code:

response.getHeaders('Set-Cookie').each {
       def cookie = it.value.split(';')[0]
        if (!cookie.startsWith('PD_')) cookies.push(cookie)
            c = c + cookie + '; '
 }
 //using the cookies, retrieve the auth tokens
 return httpPost([
     uri: "https://my-digitallife.att.com/penguin/api/authtokens",
     headers: [
               "Referer": "https://my-digitallife.att.com/dl",
               "contentType": "application/json",
               "requestContentType": "application/x-www-form-urlencoded",
               "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36",
               "DNT": "1",
               "Cookie": c
      ],
      body: "domain=DL&appKey=TI_3198CF46D58D3AFD_001"
 ]) { response2 ->

Any advice?

Remove these from the headers map, add them to the main map.

Just did the upgrade as well and getting flooded with this same issue.

Same here - seeing the same HttpResponseException issue in my logs and sluggish Alexa responses.

See below. The Hubitat team is aware the issue and is working on a hotfix.