HI Appian team,
I need help from you to show custom error message in a web api, i have asked the same question 4 months ago, in that i got a suggestion that to create an expression rule and validate the api using that ,but where i can use expression rule in an API, Please find the code attached to understand webapi code and expression rule i created. How can i call the expression rule within webapi to validate API for errors,Is anyone have done similar requirement ,if yes please post code snippet for us.
thanks
a!startProcess( processModel: cons!PF_Create_Request_WithChanges, processParameters: a!fromJson( http!request.body) , onSuccess: a!httpResponse( statusCode: 200, headers: { a!httpHeader(name: "Content-Type", value: "application/json") }, body: a!toJson( fv!processInfo ) ), onError: a!httpResponse( statusCode: 500, headers: { a!httpHeader(name: "Content-Type", value: "application/json") }, body: a!toJson( { error: "There was an error starting the process" } ) ) )
if( rule!GLB_isBlank( ri!PF_Request.GBEID ), a!toJson( { field: ri!PF_Request.GBEID, error: "Error in GBEID field" } ), true() )
Please find the above code for web api and expression rule please guide us.
please find the url below for my previous post.
https://community.appian.com/discussions/f/process/22021/how-to-show-the-specific-custom-error-message-for-an-appian-web-api-which-is-used-for-creating-records-in-appian
Thanks & Regards
Sunu Sam
Discussion posts and replies are publicly visible
A Web API is just a piece of expression code evaluated when called. This means, you can create local variables etc. as in any other expression.
- pass incoming data to expression and store the result in a local
- if validation is OK, return positive message
- If validations fails, return JSON containing one or more error messages.
Thanks Stefan for the reply, am confused in terms of the input data, my input is just a json body, how can i get the table and its corresponding column values as parameters,can you help me with the code snippet for the above explanation, for me to understand better.
processParameters: a!fromJson(http!request.body), - this is input how can i pass this to an expression rule for validation of the data??
Thanks
a!localVariables( local!validationresult: rule!yourValidationRule( input: a!fromJson(http!request.body) ), if( <validation ok>, a!startProcess( . ), a!httpResponse( /* Error Messages */ ) ) )
Thanks you Stefan, I will try the above code snipet in the webAPI.