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 :
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 } ) ) )
Discussion posts and replies are publicly visible
Did you test that API with the targetIp set to null?
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.
You can test your API from inside the Web API Designer. I suggest to use this to make it behave as expected.
Are you able to connect to the API via integration for any other case?
Yes, the issue here is that the code doesn’t check if http!request.queryParameters.targetIp is null before using it. When the value is null, the split function breaks because it can’t handle null inputs. This could be a possible reason you’re getting a 500 error from this API.