0

I need to send PATCH request with the following JSON data:

${jsonString}  Set Variable  [{"alias":"EMAIL_ORDER_CONFIRMATION","templateId":"${templateId}"}]
${resp}=  Patch Request   httpbin    /templates   data=${jsonString}    headers=${headers}

But when I run the test I am getting error message: [ ERROR ] Parsing of dictionary [{"alias":"EMAIL_ORDER_CONFIRMATION","templateId":"12345678-1111-1111-1111-11111111"}] failed. | FAIL | java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]

As I understood the problem is that my JSON file contains [], but I need to handle this some how. I am using HttpRequestLibrary, because our project is Java based and I can't use python based robot libraries.

Only one solution what I found is using files=${files} instead data=${jsonString}:

${data}=  Get Binary File  ${CURDIR}${/}..${/}resources${/}${jsonImportFile}
${files}  Create Dictionary  file   ${data}
${resp}=  Patch Request   httpbin    /templates   files=${files}    headers=${headers}

didn't help, body is empty with this approach and I am getting PayLoad validation error.

Does anybody had this problem? If so please help how to deal with this type of JSON file

Dima Zeuge
  • 79
  • 1
  • 1
  • 7
  • This sounds like the data you're giving the server is not in the format it expects. Do you have an example of data that works when using some other tool? – Bryan Oakley May 08 '18 at 17:00
  • When you say _"our project is Java based and I can't use python based robot libraries."_, does that mean you're running with jybot? You can certainly test servers written in Java with python based tools. – Bryan Oakley May 08 '18 at 17:01
  • judging by the examples in the HttpRequestLibrary, it looks like `data` is expected to be a dictionary rather than a list. Have you tried to construct a proper dictionary before calling `Patch Request`? An example can be found here: https://github.com/Hi-Fi/robotframework-httprequestlibrary/blob/master/src/test/robotframework/acceptance/Patch.robot – Bryan Oakley May 08 '18 at 17:03
  • The data I am giving is 100% in the format server expects to get. If I send the same request with the same payload: [{"alias":"EMAIL_ORDER_CONFIRMATION","templateId":"12345678-1111-1111-1111-11111111"}] via swagger for example - it works fine, because it should be a list. I am running tests via Gradle job: gradle runSmokeTests, because our test suit is inside spring project. – Dima Zeuge May 09 '18 at 07:16
  • And yes of course I tried with proper dictionary like in example which you posted, and it didn't work. It shows validation message : "status_code": 400, "text": "{\"status\":400,\"type\":\"bad_payload_syntax\",\"message\":\"Request body is missing or malformed.\",\"moreInfo\":\"\",\"details\":[]}", because payload is not in a proper format, [ ] is missing. Therefore I am looking for the solution how to handle list in data – Dima Zeuge May 09 '18 at 07:21
  • small update...after some investigation it looks like HttpRequestLibrary java library has an issue that doesn't allow to use list in data...I've tried the same scenario by using python based RequestsLibrary and it works properly. – Dima Zeuge May 09 '18 at 08:46
  • Yes, it looks like the library does not support anything but a java map/python dict as the json enclosure. The error most probably comes [here at this line](https://github.com/Hi-Fi/robotframework-httprequestlibrary/blob/master/src/main/java/com/github/hi_fi/httprequestlibrary/utils/Robot.java#L43), and there is a good explaination why [here](https://stackoverflow.com/a/33621809/3446126). In Java, being a statically typed language, this limitation won't be trivial to overcome; I'd suggest you file an issue to the lib developer. Any move to RF on python, if that's an option. – Todor Minakov May 09 '18 at 17:38
  • Thank you @Todor – Dima Zeuge May 11 '18 at 09:00

0 Answers0