Hello.
I am making calls with an integration to an external system and I am unable to use Appian's built-in JSON formatter to do so. As far as I have read on the documentation, I am also unable to do the type of string manipulation necessary to dynamically construct the JSON from scratch so that it is compatible. I am only able to statically send text as JSON for it to work.
Here are the bodies and results for a success and failure:
Body (Content Type: JSON):
"[ { ""startPublicationDate"": ""2021-09-05"", ""endPublicationDate"": ""2021-09-05"" } ]"
Result:
concat( "[ ", a!toJson( value: a!map( startPublicationDate: concat( text(ri!startPublicationDate, "yyyy"), "-", text(ri!startPublicationDate, "mm"), "-", text(ri!startPublicationDate, "dd") ), endPublicationdate: concat( text(ri!endPublicationDate, "yyyy"), "-", text(ri!endPublicationDate, "mm"), "-", text(ri!endPublicationDate, "dd") ) ) ), " ]" )
Again, the default Appian JSON format does not work (a!toJSON) and both bodies are validated JSON. How can I manipulate a string that contains quotes such as a JSON? If that is not possible, how else could I dynamically construct the JSON so that the external system accepts it?
Thanks.
Discussion posts and replies are publicly visible
The JSON you constructed is anyway not valid. If you try to pass it in a!fromJson, it will give you an error. Rather, use the below code snippet. I have tried to simply it also for you.
a!toJson( value: { a!map( startPublicationDate: text(ri!startPublicationDate, "yyyy-mm-dd"), endPublicationdate: text(ri!endPublicationDate, "yyyy-mm-dd") ) } )
Some information about JSON -
I have tried that code before and it gives the same error as in the posted screenshot. However, creating an expression and calling it in the integration body works:
Expression (ABC_SearchParams):
a!localVariables( local!startDt: todate("05/09/2021"), local!jsonArray: append( {}, { "startPublicationDate": text(local!startDt, "YYYY-MM-DD"), "endPublicationDate": text(local!startDt, "YYYY-MM-DD") } ), local!jsonArray )
Integration Body (Content Body: JSON):
rule!ABC_SearchParams()
There shouldn't be a reason why one is working and the other one is not. There must be a problem with the body you are passing.
the working code uses "endPublicationDate", while the failing code uses "endPublicationdate". Do you spot the difference?
I had not spotted the difference, the second body with the concat() function works now that I have fixed it. Thank you!