none
Reding using JSONPath in liquid template in APIM

    Question

  • Hi ,

     I have an API that return json response. I am creating the response using liquid template in outboud policy. 

    This woks great.

    Next to this what I am trying to do is implement lookup for some codes using another message. I have the message in place and want to use say message2 in my api response 

    res 1:

    {

    "mycode" : "01"

    }

    message 2:

    {

    "code": "01",

    "description": "great"

    }

    what i want is somthing like:

    {

    "code" : "01"

    "description": message2[code=mycode].descrption

    }

    How do we do lookups like this in APIM policy ?


    Pi_xel_xar

    Blog: My Blog

    BizTalkApplicationDeploymentTool: BizTalk Application Deployment Tool/

    Wednesday, December 5, 2018 7:39 AM

Answers

All replies

  • Where do you have the message available? As a variable?
    Thursday, December 6, 2018 1:14 PM
    Moderator
  • Ya Message 1 is in a variable.

    Message 2 is the response body in the outbound policy


    Pi_xel_xar

    Blog: My Blog

    BizTalkApplicationDeploymentTool: BizTalk Application Deployment Tool/

    Thursday, December 6, 2018 1:16 PM
  • I guess there could be multiple ways of doing this. Here is one that works

    <policies>
        <inbound>
            <base />
            <set-variable name="temp" value="{&apos;a&apos;:1,&apos;b&apos;:&apos;test&apos;}" />
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
            <return-response>
                <set-status code="200" reason="valid" />
                <set-body>@{
                    JObject data = JObject.Parse((string)context.Variables["temp"]);
                    return new JObject(
                        new JProperty("x", data.GetValue("b"))
                    ).ToString();
                }</set-body>
            </return-response>
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>

    Thursday, December 6, 2018 2:53 PM
    Moderator
  • I need to have this in liquid template set-body.

    I am doing mapping in outboud set-body using liquid template. 

    As an expression it works but within liquid i need to read variable as JObject & JSONPath


    Pi_xel_xar

    Blog: My Blog

    BizTalkApplicationDeploymentTool: BizTalk Application Deployment Tool/

    Thursday, December 6, 2018 6:27 PM
  • I was able to do it in a different way.. So closing the thread..

    I combined the two responses as a composite response in set-boy .

    Then used normal liquid over the combined json.


    Pi_xel_xar

    Blog: My Blog

    BizTalkApplicationDeploymentTool: BizTalk Application Deployment Tool/

    • Marked as answer by Pi_xel_xar Thursday, December 13, 2018 8:46 AM
    Thursday, December 13, 2018 8:45 AM