webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Add new field to native API JSON response payload

    Posted Fri April 14, 2023 07:55 PM

    Hello Community
    I would like to know if it is possible in API gateway (v10.11) to modify native API JSON response by adding one or more JSON fields/attributes in that response (native API’s response)?

    This addition is required before our API sends final response to the consumer. For example, this addition of new fields to native response can be done in response processing stage.

    Suppose original native API response is as following:
    {
    “employee”: {
    “id”: 1,
    “name”: “MyName”,
    “dept”: “HR”,
    “type”: “permanent”
    }
    }

    Now, suppose I want to add one new JSON field (e.g. “age”) in above mentioned JSON response at run time, so that final response of our API becomes something like following:

    {
    “employee”: {
    “id”: 1,
    “name”: “MyName”,
    “age”: 40,
    “dept”: “HR”,
    “type”: “permanent”,
    “grade”: 4
    }
    }

    Please let me know if that is doable in API gateway? If yes, then please guide me how to do it.
    Thanks


    #webMethods
    #API-Gateway


  • 2.  RE: Add new field to native API JSON response payload

    Posted Mon April 17, 2023 12:19 AM

    hi @Mubarik ,
    The transformation policies (Request Transformation and Response Transformation) supports transformation of payload only using XSL Transformation. If you are using the on prem version of API Gateway and you want to do the payload transformation without using XSL files, by directly setting a value for the payload, you can use the webMethods Invoke IS policy in API Gateway.

    Regards
    Vikash Sharma


    #webMethods
    #API-Gateway


  • 3.  RE: Add new field to native API JSON response payload

    Posted Wed April 19, 2023 04:03 AM

    Hello @Vikash_Sharma1
    Thanks for your response. Invoke IS policy seems viable solution. Can you pls let me know few high level steps to add a json attribute in existing request payload inside “flow” service?

    I know how to access request payload inside flow service when using Invoke IS policy.

    However I am not sure how to add json attribute to that captured payload inside flow service. Please note that here I am requesting info about few very high level steps only (just to get an idea/direction).

    Once I get high level idea/direction to do it inside flow service then I can work on details using webMethods documentation.
    Thanks


    #webMethods
    #API-Gateway


  • 4.  RE: Add new field to native API JSON response payload

    Posted Wed April 19, 2023 05:06 AM

    Hi @Mubarik,
    It all depends upon what all actions and transformation you want to implement on the request payload.
    One of the ways could be append the document inside the flow service and then map that appended document with the output of the flow service.

    Regards
    Vikash Sharma


    #webMethods
    #API-Gateway


  • 5.  RE: Add new field to native API JSON response payload

    Posted Mon April 17, 2023 10:58 AM

    I would advise against doing this. In general, API Gateway should be a “gatekeeper” not an active participant. Pass things through, don’t manipulate things – let whatever implements the API do that.

    Of course there are times and scenarios where API GW is the only spot available where you might have control to do something. But if at all possible, have the “do something” be elsewhere.


    #API-Gateway
    #webMethods


  • 6.  RE: Add new field to native API JSON response payload

    Posted Wed April 19, 2023 06:29 AM

    Yes, it’s possible to modify the native API JSON response by adding one or more JSON fields or attributes in the response using API Gateway v10.11.

    One way to achieve this result is by using the API Gateway’s policy framework for manipulating the JSON response. You can use the “JSON Transformation” policy to modify the JSON response and add extra fields or attributes to it. This policy allows you to add, remove, or modify JSON elements in the response body based on certain conditions.

    Here’s an example of how you can use the “JSON Transformation” policy to add a new JSON field to the response:

    Add New Field new_field_name new_field_value

    In this example, the policy adds a new field called “new_field_name” with a value of “new_field_value” to the JSON response. You can customize the policy to add multiple fields or modify the existing fields as needed.

    Once you’ve added the policy to your API Gateway configuration, it will be applied to all the requests to the API, and the modified JSON response will be sent to the consumer.


    #API-Gateway
    #webMethods