Jeremy_MONZO | 2020-07-20 13:47:15 UTC | #1
Hello,
I would like create a data action with an input contract which accepts null value. My use case is the following : if the value is filled it gives a result if not , a result is given with a defaut value
In my example, I have made test with the input contract tAcw. When I configued with no value, I get this error :
8. Execute: The request could not be understood by the server due to malformed syntax.
- REST call for action execute failed. Message:Request to backend service failed. Response from web service: {"message":"Must populate at least one of the parameters [gt, gte, lt, lte]","code":"bad.request","status":400,"messageParams":{},"contextId":"1240ab46-0190-4225-ad1a-3ce2716a6237","details":[],"errors":[]} [ad5abbb0-c1fc-48fe-920c-6c345b916328]
I have configured the request body template with this code for the tAcw which should accept "null" value { "type": "metric", "metric": "tAcw", "range": { "lte": "#if( ${input.tAcw} )${input.tAcw}#else ${input.tAcw}=10#end" } }
I have attached the export action for more details
Many thanks for your hints jeremy
Jeremy_MONZO | 2020-07-20 13:48:22 UTC | #2
POST-TEST-NULL-value-20200720154152.custom.json|attachment (4.0 KB)
Jerome.Saint-Marc | 2020-07-20 14:58:34 UTC | #3
Hello,
There might be other ways to do this. But I tried the following (Request Configuration - text below is when using Simple definition) and it seems to work.
"lte": "#set( $mydefault = "10" )#if( ${input.tAcw} )${input.tAcw}#else$mydefault#end"
Regards,
Jeremy_MONZO | 2020-07-20 15:24:46 UTC | #4
Hi Jerome,
thanks for your help I have replaced by your suggestion int the Request Body Template, but now I get this error :
2. Validate draft definition: The request could not be understood by the server due to malformed syntax.
- Action POST TEST NULL value failed validation. Errors: [Template validation failed for 'config.request.requestTemplate'. Details: Encountered "mydefault" at validate config.request.requestTemplate[line 55, column 20] Was expecting one of: <IDENTIFIER> ... "{" ... ]
It seems there is a problem with the variable mydefault, do you have made modification from my data Action sent?
thanks jeremy
Jerome.Saint-Marc | 2020-07-20 15:36:27 UTC | #5
Sorry, the \$ sign got removed when I did the cut&paste from my data action to the forum (forgot to escape the $ to keep it displayed).
"lte": "#set( \$mydefault = "10" )#if( \${input.tAcw} )\${input.tAcw}#else\$mydefault#end"
Jeremy_MONZO | 2020-07-20 15:56:56 UTC | #6
Many thanks it works! Jerome, you talked me about other ways for achieve this request, you can told me a little more? thanks again!
Jerome.Saint-Marc | 2020-07-20 16:06:59 UTC | #7
I meant that there might be other ways that I don't know. :slight_smile: First time I tried a velocity if/else to replace a null value.
I did try (unsuccessful) to put the value directly after the else (without going through the mydefault variable). I could make it work when the value was string with a to z characters. But it didn't work with the integer value. So instead of trying to figure out if this could be done that way, I preferred to use the variable and #set (which worked).
Jeremy_MONZO | 2020-07-20 16:18:35 UTC | #8
From my side, tested many things without success :wink: thanks :+1:
system | 2020-08-20 16:18:36 UTC | #9
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 8336