2
votes

I have created an API in the WSO2 ESB (4.8.1) and I wanted to send a PUT request to that API with a request body. I have tried with the sample and I wanted to log a property values in the insequence of the defined API.

This is my request body:

request body (JSON)

This is the way how I tried to log the location name:

XML log

But Iā€™m getting an error like this:

(ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path . Returning empty result. Error>>> invalid path)

error screenshot

So how can I read these values?

2
Since the images you posted show text only, you probably should edit your question to include the actual text, so that both request and errors become searchable. ā€“ dakab
thanks for suggestion. I have taken the request from the given link in my question. When i'm trying to post as a text getting an error saying that my code to be formatted. that is why I added a print screen ā€“ Anushka Ekanayake
can you confirm that $. print in the log the full JSON payload? ā€“ Jorge Infante Osorio

2 Answers

5
votes

To achieve your requirement, you should send the "Content-Type" HTTP header with the request like below,

    "Content-Type : application/json"

enter image description here

Then you can log the specific JSON element like below.

 <log>
    <property name="location" expression="json-eval($.coordinates.location[0].name)"></property>
 </log>

Then you can see following log,

enter image description here

Thanks.

1
votes
If you want to get single variable from user in json request you can use this code 


Use This json:
    {

    "namee":"UsmanYaqooooooooooob"
    }


Api Code: 
        <api xmlns="http://ws.apache.org/ns/synapse" name="Hello" context="/hello">
           <resource methods="POST" uri-template="/post">
              <inSequence>
                 <log level="custom">
                    <property name="===========inSequence" value="****"></property>
                    <property name="locationsssssssss" expression="json-eval(.namee)"></property>
                 </log>
                 <payloadFactory media-type="json">
                    <format>{"hello":"world"}</format>
                    <args></args>
                 </payloadFactory>
                 <property name="messageType" value="text/xml"></property>
                 <respond></respond>
              </inSequence>
           </resource>
        </api>