Document Upload WEB API Returning Success on empty body

Certified Associate Developer

Hello,

I have a handler for document upload WEB API that has validation if the binary body is empty. The problem is in Appian, the validation is working but in Postman, it returns success even when the body is empty.

a!localVariables(
  local!params: property(ri!request, "queryParameters", null),
  local!body: property(ri!request, "body", null),
  local!fileName: property(local!params, "filename", null),
  local!transactionId: property(local!params, "transactionid", null),
  local!docCategoryId: property(local!params, "doccategoryid", null),
  local!docTypeId: property(local!params, "documenttypeid", null),
  local!validation: reject(
    fn!isnull,
    {
      if(
        or(
          a!isNullOrEmpty(local!transactionId),
          a!isNullOrEmpty(local!docCategoryId),
        ),
        "Missing Parameters. Please Try Again",
        if(
          or(
            a!isNotNullOrEmpty(local!docTypeId),
            a!isNotNullOrEmpty(local!fileName)
          ),
          if(
            a!isNullOrEmpty(local!body),
            "Missing Body. Please try again.",
            null
          ),
          null
        )
      )
    }
  ),
  if(
    length(local!validation) > 0,
    rule!REST_JsonResponse(
      statusCode: 400,
      body: {
        title: "Missing Parameters Error",
        message: local!validation[1],
        code: cons!CSB_COMMONS_ERROR_CODE_MISSING_PARAMETERS
      }
    ),
    a!startProcess(
      processModel: cons!RMS_UploadDocument_PM,
      processParameters: {
        fileName: tostring(local!fileName),
        document: local!body,
        transactionId: tointeger(local!transactionId),
        documentType: tointeger(local!docTypeId),
        docCategory: tointeger(local!docCategoryId),
        
      },
      onSuccess: if(
        or(
          a!isNullOrEmpty(local!docTypeId),
          a!isNullOrEmpty(local!body)
        ),
        rule!REST_JsonResponse(
          statusCode: 200,
          body: {
            transactionId: local!transactionId,
            documentCategory: fv!processInfo.pv.documentCategoryStatus_CDT.category,
            documentTypes: a!forEach(
              items: fv!processInfo.pv.documentTypeUnderCategoryTransaction_CDT,
              expression: fv!item.documentTypeId
            )
          }
        ),
        rule!REST_JsonResponse(
          statusCode: 200,
          body: {
            transactionId: local!transactionId,
            documentId: fv!processInfo.pv.document_CDT.id,
            fileName: fv!processInfo.pv.document_CDT.fileName,
            fileExtension: fv!processInfo.pv.document_CDT.fileExtension,
            createdDate: fv!processInfo.pv.document_CDT.createdDate,
            approvalDate: fv!processInfo.pv.document_CDT.approvalDate,
            expirationDate: fv!processInfo.pv.document_CDT.expirationDate,
            documentType: fv!processInfo.pv.document_CDT.documentType.documentTypeId.documentType,
            documentCategory: fv!processInfo.pv.document_CDT.documentType.categoryId.category.category,
            filePath: fv!processInfo.pv.document_CDT.filePath,
          }
        )
      ),
      onError: rule!REST_JsonResponse(
        statusCode: 500,
        body: {
          title: "Internal Server Error",
          message: "Unknown error occured. Please contact the Administrator",
          code: cons!CSB_COMMONS_ERROR_CODE_UNKNOWN_ERROR
        }
      )
    )
  )
)

As you can see, it still returns status 200

But in Appian, the validation is working

This also happens even in the default expression of the Document Upload web API.

  Discussion posts and replies are publicly visible