generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
Hi,
It seems that when following the example to create a update msg yields something like
"{"status":"SUCCEEDED","statusDetails":"{"key":"value"}"}}
Now, I don't know how you expect the MQTT API to be like, but in my case having a JSON content enclosed in quotes ("{"key":"val"}") is not working. I think it is safe to assume that job details will always be formatted as JSON and hence these quotes should be omitted.
If you don't agree I'll just use a local patch, so let me know :)
All the best
Ref:
* const char * expectedVersion = "2";
* const chat * statusDetails = "{\"key\":\"value\"}";
* char messageBuffer[ UPDATE_JOB_MSG_LENGTH ] = {0};
* size_t messageLength = 0U;
*
* JobsUpdateRequest_t request;
* request.status = Succeeded;
* request.expectedVersion = expectedVersion;
* request.expectedVersionLength = ( sizeof( expectedVersion ) - 1U );
* request.statusDetails = statusDetails;
* request.statusDetailsLength = ( sizeof( statusDetails ) - 1U );
*
* messageLength = Jobs_UpdateMsg( request
* messageBuffer,
* UPDATE_JOB_MSG_LENGTH );
*
* if (messageBufferLength > 0 )
* {
* // The message string of length, messageLength, has been
* // generated in the buffer, messageBuffer, for the UpdateJobExecution API
* // Publish this message to the topic generated by Jobs_Update using an
* // MQTT client of your choice.
* }
* @endcode
*/
/* @[declare_jobs_updatemsg] */
size_t Jobs_UpdateMsg( JobsUpdateRequest_t request,
char * buffer,
size_t bufferSize );
Activity
ActoryOu commentedon Jul 30, 2024
Hello @TheCrazyKing,
Thanks for bringing this into our attension! I've verified that example and it's also failure in my case.
I'll create a PR to fix that.
The problem of this example is not the quote, and the
statusDetailsis also expected to be JSON format (checked by areOptionalFieldsValid()). Note that the expected result would be:{"status":"SUCCEEDED","expectedVersion":"2","statusDetails":"{"key":"value"}"}.Thank you.
TheCrazyKing commentedon Jul 30, 2024
Ok! I saw your PR and it indeed corrects a bug. Now, I had just this question regarding the quotes if I may:
when publishing (with the AWS IoT MQTT test client) to the jobs update topic, the following content throws an error (
{ "code": "InvalidJson", "message": "Unexpected character ('p' (code 112)): was expecting comma to separate Object entries at [Source: (iot.laser.tjm.handler.utils.DeviceMessageParser$1); line: 1, column: 68]" }):{ "status":"IN_PROGRESS", "statusDetails": "{"progress":"testerQuotes"}" }but the following message format is working:
{ "status":"IN_PROGRESS", "statusDetails": {"progress":"testerQuotes"} }Is it still compliant with the expected result
{"status":"SUCCEEDED","expectedVersion":"2","statusDetails":"{"key":"value"}"}you mentioned ? Or am I missing something here ?PS: the message format
gives this error
"code": "InvalidRequest","message": "Value at statusDetails cannot be a STRING for topic $aws/XXXaggarg commentedon Jul 30, 2024
This is not a valid JSON. You can check that using any JSON validator - https://jsonformatter.org/json-pretty-print.
ActoryOu commentedon Jul 31, 2024
Hi @TheCrazyKing,
"{"progress":"testerQuotes"}"is not a valid JSON, as @aggarg said.When we declare a char string like
const chat statusDetails[] = "{\"key\":\"value\"}";, the string is actually{"key":"value"}. No quote at the begining and no quote at the end.Thank you.
ActoryOu commentedon Jul 31, 2024
Closing because it's resolved.
TheCrazyKing commentedon Jul 31, 2024
@ActoryOu
Ok but the SDK (JobsUpdateMsg) will enclose the status details JSON with quotes:
#define JOBS_API_STATUS_DETAILS "\",\"statusDetails\":\""and at the end of the function:
( void ) strnAppend( buffer, &start, bufferSize, "\"}", ( CONST_STRLEN( "\"}" ) ) );I would apply a patch like this one:
If you append
\"after the job status details, there will be a quote after the JSON status detail.If you do not agree, I'll use the patch only locally.
All the best
Fix Jobs_UpdateMsg to generate valid JSON
aggarg commentedon Jul 31, 2024
You are exactly right. This PR addresses the issue - #109.
Thank you for reporting it.
Fix Jobs_UpdateMsg to generate valid JSON (#109)