Skip to main content
Known Participant
Jan 3, 2025 6:06 PM UTC
Question

Web API for portal Email validation

Hi Experts,

I have created a WEB API in which i am validating IP Address and email. Based on that I have created Integration which called that WEB API . Then In integration if I pass IP parameter null and only email is passes than it gave an error. 

Please help me how can handle it .

Below is WEB API :

a!localVariables(
  local!invalidipAddress: a!flatten(
    a!forEach(
      items: split(
        split(
        http!request.queryParameters.targetIp,
        " "
      ),
      char(10)
      ),
      expression: rule!CDM2_ER_IP_Address_Validator(fv!item)
    )
  ),
  local!isInvalidEmail: if(
    a!isNotNullOrEmpty(http!request.queryParameters.email),
    not(rule!CDM2_ER_Email_Address_Validator(http!request.queryParameters.email)),
    false() /* If no email is provided, assume valid */
  ),
  local!confirmIP: {
  ipInfo:if(
      and(
        a!isNotNullOrEmpty(http!request.queryParameters.targetIp),
        length(local!invalidipAddress) > 0
      ),
      "Entered IP Addresses either Invalid or Private IP Addresses :  " & local!invalidipAddress,
      /*false(),*/
      true()
    ) ,
    emailInfo: not(local!isInvalidEmail) /* True if email is valid */
  },
  a!httpResponse(
    statusCode: 200,
    headers: a!httpHeader(
      name: "Content-Type",
      value: "application/json"
    ),
    body:a!toJson(
      {
        ipValidation: local!confirmIP.ipInfo,
        emailValidation: local!confirmIP.emailInfo
      }
    )
  )
)

Integration Error :

5 replies

stefanhelzle0001
Brainy
Jan 3, 2025 6:37 PM UTC

Did you test that API with the targetIp set to null?

Known Participant
Jan 5, 2025 2:14 PM UTC
I am calling this web api on two different interfaces. I want that if any one of the parameters is missing then also the integration given success true.
stefanhelzle0001
Brainy
Jan 5, 2025 4:26 PM UTC

You can test your API from inside the Web API Designer. I suggest to use this to make it behave as expected.

somasundaram.d
Employee
Jan 6, 2025 6:38 AM UTC

Are you able to connect to the API via integration for any other case?