2
votes

I use wso2 API manager for publishing some of my APIs. But my issue is if someone send a API request with invalid json body, is it able to ignore that API call and give some error message to the requested person without sending that invalid json body to the back end. API manager version : 1.7

  • This is the incorrect json request (try to send without value for "moduleCode")

    {
    "event": {
        "portalType": "dfd",
        "moduleCode": ,
        "role": "3",
        "roleCode": "dfdf",
        "languageID": "gd",
        "password": "dfdfgd",
        "phoneNumber": "2332323",
    
        "resourceCode": [
            "8045005"
        ]
    
    
    }}
    

Could it possible to restrict user by value of role in the above json ? How to achieve this with API Manager 2.0 ?

3

3 Answers

2
votes

Thre aren't any predefined way to achieve this requirement. But, You can customize WSO2 API Manager to cater this requirement.

You can write a custom handler which will validate the request body and return response if the request has some error rather sending to backend. You can check here on how to write a custom handler for API Manager 2.0.

1
votes

You can refer this article on "How to validate JSON request payload in API Manager". This is exactly address your use case and only thing you need to do is add XSD to match with your request. In API Manager if you need to validate request or pre process message its always recommend to use mediation extensions available with the product.

0
votes

In coming request will be transform to SOAP format by message builder[1].This message builder will be chosen based on the content type of incoming message.You can write your own message builder for application/json and validate the input. e.g [2]

[1]https://docs.wso2.com/display/ESB481/Working+with+Message+Builders+and+Formatters [2]https://github.com/anuruddhal/WSO2-ESB-Custom-Message-Builder/tree/master/CustomBuilder