Call DMN rule from Postman using a "Date" field

I have the following parameters in a POST:
{“variables”:
{
“acct_safekeep”:{“value”:“STT”, “type”:“String”},
“share_price”:{“value”:65.0, “type”:“Double”},
“trade_date”:{“value”:“2019/01/31”, “type”:“Date”}
}
}

However, I get an error when I send it:
{
“type”: “InvalidRequestException”,
“message”: “Cannot convert value ‘2019/01/31’ of type ‘Date’ to java type java.util.Date”
}

the decision table is as follows:

please help.

Hey,

one simple idea would be to pass “2019/01/31” as a string and then once you have received the request transform the string to a date

String string = "2019/01/31";
DateFormat format = new SimpleDateFormat("yyyy/mm/dd", Locale.ENGLISH);
Date date = format.parse(string);

Cheers,
Sascha

Sasha thanks for getting back quickly.
I don’t see where I would do the conversion. from string -> Date.
Does the conversion take place in the rule? Where would this code be placed?

String string = "2019/01/31";
DateFormat format = new SimpleDateFormat("yyyy/mm/dd", Locale.ENGLISH);
Date date = format.parse(string);

Based on the exception you get, I assume your server uses Java and expects “java.util.Date” whereas in the decision table the typeRef declares “date”. This is most likely the reason the value of “2019/01/31” can not be properly resolved.

My suggestion would be to change the typeRef to use a string and then let the server expect a string. This allows you to receive your POST request and then change the string to Java’s date format.

Btw, do you have access to the server (where the call will be resolved)?

Does the conversion take place in the rule? Where would this code be placed?

On the server :slight_smile:

there is no server - it is the DMN runtime that is handling the REST call.

From the documentation:

Working with Dates

The DMN engine supports a date type which is a combination of date and time. By default, the data type transformer accept objects of the type java.util.Date and Strings having the format yyyy-MM-dd'T'HH:mm:ss .

If you prefer another format or different representation of a date, implement a custom type and replace the default transformer.

In that case you have to change the value of your date to conform to the expected format, as described above.

right…the issue is sending the data from postman or curl. how do you represent a Date?

As far as I know (not really sure here), Java uses the ISO 8601 standard for dates. That means you have to pass your date to the DMN in accordance to those formats

If you change the date format to

{
  "variables": {
    "acct_safekeep": {
      "value": "STT",
      "type": "String"
    },
    "share_price": {
      "value": "65.0",
      "type": "Double"
    },
    "trade_date": {
      "value": "2019-01-31",
      "type": "Date"
    }
  }
}

This might already work (at least I hope so) :smiley:

@airazabal, the date format should match ISO 8601 date format.

Like this: 2019-01-31T10:11:00.000+0100

{
  "businessKey": "5c432441778531931cd639865",
  "variables": {
    "timerDate": {
      "type": "Date",
      "value": "2019-01-31T10:11:00.000+0100"
    }
  }
}

Thanks, that got me through the original issue. I am now getting a { "type": "RestException", "message": "Cannot evaluate decision ae914c03-2890-11e9-9283-0242ac110002: Exception while evaluating decision with key 'null'" }
what is the best way to debug this? logs? debug output? How do I know which key is null?

so I looked at the logs in the container, and I see this cryptic message:
Caused by: org.camunda.bpm.dmn.feel.impl.juel.FeelMissingVariableException: FEEL-01009 Unable to resolve variable ‘STT’ in expression ‘STT’
STT should be the value of the field “account”, why does it think it is a variable?
Caused by: org.camunda.bpm.dmn.feel.impl.juel.FeelMissingVariableException: FEEL-01009 Unable to resolve variable 'STT' in expression 'STT'

Can you upload your DMN to analyze?

Market_Validation_Decision.dmn (2.6 KB)

Try this DMN and let me know if any issues.

Market_Validation_Decision.dmn (2.7 KB)

I re-deployed your version and send a postman “POST” with the following:
{“variables”:
{
“acct_safekeep”:{“value”:“STT”, “type”:“String”},
“share_price”:{“value”:“65.0”, “type”:“Double”},
“trade_date”:{“value”:“2019-01-31T10:11:00.000+0100”, “type”:“Date”}
}
}
I got the same error.
I am calling it with: http://localhost:8080/engine-rest/decision-definition/cd9eb237-2951-11e9-9283-0242ac110002/evaluate

“share_price”: { “value”: “65.0”, “type”: “Double” },

From your payload, try sending with proper precision for double value as 65.00

same thing or perhaps I should say same problem…

In your DMN, what condition you’re evaluating in 2 nd row?

Can you explain this?

image

a range between 65 and 85

Market_Validation_Decision.dmn (2.7 KB)

Try with this