API Data Page - Allow validation of parameters?

What I want to achieve?

I want to define API with date parameter:

/api/public/mydatapagemethod?dateFrom={dateFrom}

The API works fine when the parameter is in correct format (yyyy-MM-dd or yyyy-MM-ddTHH:mm:ss). If the format is not correct, then it leads to server internal error which is not something you would like to show to the end API user.

Validation Rule

I have tried to use Input Validation Rule which return readable exception but the context of the rule is empty when I trace it (<ROOT />). So it means it is designed only for request body but not parameters.

Is there any way how to validate API input parameters? I guess at the moment the only way is to create Workflow Method with check rule. I did it and it works as expected, I pass the parameter to the string context and then verify inside workflow using (Task) check rule step inside the workflow.

Suggestions?

It is not a lot of effort to create Workflow method, validate parameters and call Load method to load data. But I think whether it should be even simpler?

For example define data type of API parameter or add validation rule directly to the parameter and validate it as a Simple Context (/ROOT/value).

That would bring parameters’ validation to simple Data Page Workflow without need to define Workflow method but only define simple validation rules for parameters.

This is just suggestion to streamline modeling of API, but nothing needed as the solution is available using Workflow method to load data structure.

Have you tried defining an XSLT parameter with the URL parameter’s name in the Input Validation Rule?

So for /myrequest?param1=myValue you would do

<xsl:param name="param1"/>

<xsl:template match="/">
   <xsl:if test="$param1 = 'myValue'">
      ...
   </xsl:if>
</xsl:template>

Hi Tomáš,

nice tip, thank you. This is the trick.

Good to mention that the name of parameter in xslt must be the name of the mapped parameter in API, not the URL parameter.

My URL is

/api/public/mydatapagemethod?dateFrom={dateFrom}

My API data structure method looks like this:

MyStructure

* <<Filter>> GetByDateFrom(MyEntity_parDateFrom)

The API parameter mapping looks like this (MyEntity_parDateFrom is mapped to dateFrom url parameter):

The validation rule must use MyEntity_parDateFrom parameter and then it works as expected and I can validate parameter and send proper error message to the client.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.