Passing values in json format

Hi All,

I have a requirement where i have to pass the value from variable into the webapi . I am receiving 500 error as the following code is not in Json format.

|post web api | testWebapi | with body |{"var1":tv!variable} |with username| testUsername

Did anyone of you face similar issue and how do we pass the tv!variable in Json Format.

Thanks In advance

Regards,

Sahithi

  Discussion posts and replies are publicly visible

  • Hi Sahiti,

    Could you pelase eloborate more about this issue (what is the expected request sample and what is this tv!variable contans)? are you constructing the web api request manually or else are you using any to json fucntions?
  • Hi sahithip,
    Could you please elaborate more on your use case so that it will be helpful to state the solution.

    Thanks,
    ravalik
  • Hi Shanmukha & ravalik,

    I am trying to call a webapi from Fitnesse. The syntax for this is
    | post web api | WEB_API_ENDPOINT | with body | BODY | with username | USERNAME |

    for the fitnesse to execute this step , I should be passing the values for the body in Json Format similar to
    | post web api | testwebapi | with body | {"id":"1", "Name":"Sahithi"} | with username | testUsername |

    But in my scenario i have values already generated in previous steps and stored in a variable.
    For Eg: tv!name has the value "Sahithi"
    So now i should be passing this as
    | post web api | testwebapi | with body | {"id":"1", "Name":tv!name} | with username | testUsername |

    The above syntax throws 500 error as the variable tv!name is not considered to be in Json Format for the input.

    So i was seeking help if anyone had similar situation and is able to help me.
  • Have you tried to setup the value to a variable ? And then pass to the webapi?

    I have been able to concatenarme variables before, have you tried to play with that approach? Even setting variables tv! or the $var could help.

    If I find time I can elaborate more my suggestion.

    Hope this helps
    Jose
  • 0
    Certified Lead Developer

    Hi  

    Couple of questions here:
    1. Is you Web-API trying to store the body data into the database?
    2. If so, does it's Body contain a Date / Date and Time type values converted into JSON format?
    3. If so, try defining it as null for a moment and try executing the WEB-API, but if not then i believe we need to have a look into the logs to understand the root cause behind this exception.

    Also can you please share your JSON Data here so that it will be easy to understand the actual issue.

  • Hi Josep,

    I have set up the value of the variable in the suite setup. and i am trying to cal this webapi in one of my test cases. I am facing the issue as i am not able to send the value in Json format for the webapi. It wod have been easy if i can hard code the value but i cannot do it as i receive this value from suite setup.
  • Hi Alok,

    Yes I am trying to store the body data into the database. I am passing text value(for Ex: "name":"Sshithi") as the input into the webapi and then constructing the datatype and then trying to write the constructed type into DB (using a!startprocess(). Using this as i need the Is from this as an input to next CDT) .

    I have issue while invoking the webapi as the syntax for that is | post web api | WEB_API_ENDPOINT | with body | BODY | with username | USERNAME |

    I am currently passing: |with body|{"name": tv!name}| and it is expecting Json format in the |BODY|.