asynchttpPost() method and AWS authentication problem

I'm writing a driver that will integrate with a vehicle remote starter. The remote starter API authenticates with AWS. Of course, AWS uses a content-type of "application/x-amz-json-1.1" instead of "application/json", but that content type is not supported by the asynchhttpPost() method.

When I try that request, this is the error I get: "No encoder found for request content type application/x-amz-json-1.1"

I think this is a question for the Hubitat developers specifically, but can that content type be supported in an update?

Question for the larger community, is there another way to authenticate with AWS?

I have all the API requests done in postman, and everything works there with the AWS content type. I'm able to authenticate and execute all the vehicle commands, so I know my request format and content are correct.

Let me know what other info I can provide.

Thanks! :slightly_smiling_face::beers:

Anybody? Hubitat devs?

I'm not sure that I'll be of much help.
But, can I see the code format you are using to make the request (remove any personally identifiable info)?

  • What happens if you change 1.1 to 1.0?

@joshlobe the sanitized code is below. Interesting idea about changing 1.1 to 1.0, I will try that after work.

The request works using postman or just running the JS version in the browser console, so I'm confident everything is structured correctly.

Since the error I get is "No encoder found for request content type application/x-amz-json-1.1", that makes me think that Hubitat itself doesn't support that request type.

def requestParams = [
			"uri": "https://cognito-idp.us-east-1.amazonaws.com",
			"headers": [
					"accept": "*/*",
					"Accept-Encoding": "gzip, deflate, br",
					"Connection": "keep-alive",
					"Accept-Language": "en-US,en;q=0.9",
					"Cache-Control": "no-store",
					"Content-Type": "application/x-amz-json-1.1",
					"Origin": "https://**************************",
					"Referer": "https://**************************",
					"X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth",
					"X-Amz-User-Agent": "aws-amplify/5.0.4 js",
					"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
			],
			"contentType": "application/x-amz-json-1.1",
			requestContentType: "application/x-amz-json-1.1",
			"body": [
					"AuthFlow": "USER_PASSWORD_AUTH",
					"ClientId": awsClientId,
					"AuthParameters": [
							"USERNAME": awsUsername,
							"PASSWORD": awsPassword
					],
					"ClientMetadata": []
			]
	]

	asynchttpPost("saveToken", requestParams)

Any reason your requestContentType is not wrapped in quotes?

You have content type both inside and outside of your header block. Try removing it from the header block.

@joshlobe re: quotes - quotes aren't required around keys. Stylistically I'm used to using them but I copy/pasted that line from the developer guide asynchttpPost page (which is unquoted).

@joshlobe re: 1.1 vs 1.0 - Changing it to 1.0 has no effect, hubitat still says there is no encoder.

@thebearmay re: content-type in header: i tried all combinations but the result is the same. The error message "No encoder found for request content type application/x-amz-json-1.1" to me strongly indicates that hubitat is doing some parsing/processing/encoding of the request content type, and that message smells like there is no encoder for application/x-amz-json-1.1 in and the hub doesn't know how to process the request.

@Hubitat_Staff can someone confirm from the development team confirm that my code example has the correct use of requestContentType and the problem is with a missing encoder in Hubitat itself?

Just tried it in a quick test app and didn’t recieve an error.

Interesting. What platform version are you running?

And I'm not sure if it makes a difference, but this is a device and not an app.

Does anyone have any ideas on how to solve this? @Hubitat_Staff ?