Skip to main content
January 11, 2023
Question

How to check parameter error in Web API

  • January 11, 2023
  • 2 replies
  • 0 views

Hello Appian People,

I have a test WEB API(POST) in order to test my integration process. 

I also created a test datastore.

{

user:

address:

}

Please see picture

So what i want to happend is that what to add a test process condition:

If the Request result normal, and statusCode 200 - body: received value will be "0"

Incase parameter error,and statusCode 200  - body: received value will be "1"

Anyone has any idea to add this test condition in my Test web API?

2 replies

January 11, 2023

Hi [mention:29ea91bd355e4d6c97d44017e828c0d2:e9ed411860ed4f2ba0265705b8793d05] 

If there is any parameter error , we cannot give 200 as status code , we can give 400 status code with bad request as response message.

Please refer the below sample code:

if(
  or(
    a!isNullOrEmpty(local!value.user),
    a!isNullOrEmpty(local!value.address)
  ),
  a!httpResponse(
    statusCode: 400,
    body: "Few parameters are missing-Bad request"
  ),
  a!writeToDataStoreEntity(
    dataStoreEntity: "DATASTORECONST",
    valueToStore: {"VALUES"},
    onSuccess: a!httpResponse(
      statusCode: 200,
      body: "Response for Sucess"
    ),
    onError:  a!httpResponse(
      statusCode: 500,
      body: "Internal server Error"
    )
  )
)

January 11, 2023

Hi Harshitha,

This helped, thanks a lot :)