Validate Request Parameters in Appian Web-API

Dears, I need to validate all the request parameters i.e. CaseFees is Integer or not, in case its null or not integer then the WEB-API should throw an exception and shall not proceed next.

Kindly, need an answer as soonest

 

Thanks

  • Hi asifh,
    Please let us know if this helps.
    with(
    local!task:http!request.queryParameters.taskId,
    local!taskId: tonumber(local!task),
    local!entities: if(
    rule!APN_isBlank(local!taskId),
    null,
    a!queryEntity(
    entity: cons!AMS_TASK_ENTITY,
    query: a!query(
    pagingInfo: topagingInfo(1,-1),
    filter: a!queryFilter(
    field: "taskID",
    operator: "=",
    value: local!taskId
    )
    )
    ).data
    ),
    a!httpResponse_17r4(
    headers: {
    a!httpHeader(
    name: "Content-Type",
    value: "application/json"
    )
    },
    body: if(
    rule!APN_isBlank(local!taskId),
    a!toJson_17r1(
    value: {Error:"Task Id Required please use query parameter eg: url/.../getTaskDetails

    ),
    a!toJson_17r1(
    value: local!entities
    )
    )
    )
    )
  • Hi @

    As per my understanding, to achieve this requirement, you can follow below mentioned steps:

     
    1. Retrieve the request parameter value using http! and store it into a local variable, let's say local!CaseFees.
     
    2. Use typeof(local!CaseFees) to find out the type of this value and compare this with typeof(1) , if this returns false or if the local!CaseFees is empty then use a!httpResponse to return error 500 as per your requirement.
     
    Sample Code Snippet:
     
    if(
        or(
          typeof(local!CaseFees) <> typeof(1), /* if request param is not of type Integer */
          rule!APN_isEmpty(local!CaseFees) /* or if request parameter is empty */
        ),
        a!httpResponse(
          statusCode: 500,
          body: "Parameters cannot be empty / should be of type Integer Only"
        ),
        {}
      )
     
    Note: Here local!CaseFees will hold the value of your request parameter i.e. http!request.queryParameters.CaseFees where CaseFees is the query parameter being sent from the Consumer side to this API.
     
    Hope this snippet will help you.

 Discussion posts and replies are publicly visible