asyrjasalo / RESTinstance

Robot Framework library for RESTful JSON APIs
https://pypi.org/project/RESTinstance
GNU Lesser General Public License v3.0
205 stars 84 forks source link

Post json in json #76

Closed metabsd closed 4 years ago

metabsd commented 5 years ago

The code

*** Settings ***
Library         REST    https://IP  ssl_verify=False
Library         BuiltIn

*** Variables ***
${json}             {"extra_vars": "{\"variable_1\": \"http://URL\", \"variable_2\": \"http://URL\", \"variable_3\": \"http://URL\", \"list_1\": [\"item1\", \"item2\"]}"}
${oauth_token}      SUPERDUPERTOKEN
*** Test Cases ***
Get Workflows
    REST.GET         /api/v2/workflow_jobs/       headers={ "Authorization": "Bearer ${oauth_token}" }
    Integer     response status           200
    Output
Start Add TEST Workflow
    REST.POST        /api/v2/workflow_job_templates/1/launch/   ${json}     headers={ "Authorization": "Bearer ${oauth_token}" }
    #Integer     response status           200
    Output

The Get Workflows step work perfectly but When I try to post json with json inside json I got an error because somewhere I loose the escape string. I try the same call via Postman and it's working.

The error

Input not is valid JSON: {"extra_vars": "{"variable_1": "http://URL", "variable_2": "http://URL", "variable_3": "http://URL", "list_1": ["item1", "item2"]}"}

Thx!!

metabsd commented 5 years ago

I find a way to workaround it. I double escape the thing.

${json}             {"extra_vars": "{\\"variable_1\\": \\"http://URL\\", \\"variable_2\\": \\"http://URL\\", \\"variable_3\\": \\"http://URL\\", \\"list_1\\": [\\"item1\\", \\"item2\\"]}"}