Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Passing data structures into REST calls

  • 16-03-2017 09:46AM
    #1
    Registered Users, Registered Users 2 Posts: 262 ✭✭


    See below code, specifically data part. RobotFramework does not like this.
    `* Test Cases * 
    Add Patient Log Add Patient 
    [Tags] Add_Patient 
    ${number}= Generate Random Number ${4} 
    ${data}= {"patients": [ new "sponsor": "test1", "protocol": "Blue18-B18VP1","site_number": "1001","integration_id": int_id_${number},"subject_number": "RT0001","subject_status": "T","randomization_date": "01Jan2017", "treatment_id": "B18VP2"} ]} 
    Create Session sw3 ${ENVIRONMENT_TO_RUN_AGAINST} debug=3 
    ${resp}= Post Request sw3 ${ENVIRONMENT_TO_RUN_AGAINST}/api/v1/test1/patients \ ... Content-Type:application/json \ ... Authorization:authkey02 Accept=application/json \ ... data=${data}
    

    Giving error as follows

    Creating keyword failed: No keyword with name '{"patients": [ new "sponsor": "test1", "protocol": "Blue18-B18VP1","site_number": "1001","integration_id": int_id_${number},"subject_number": "RT0001","subject_status": "T","randomization_date": "01Jan2017", "treatment_id": "B18VP2"} ]}' found.

    What is the correct syntax to add this data to the post request


Comments

  • Closed Accounts Posts: 646 ✭✭✭hungry hypno toad


    guylikeme wrote: »
    See below code, specifically data part. RobotFramework does not like this.
    `* Test Cases * 
    Add Patient Log Add Patient 
    [Tags] Add_Patient 
    ${number}= Generate Random Number ${4} 
    ${data}= {"patients": [ new "sponsor": "test1", "protocol": "Blue18-B18VP1","site_number": "1001","integration_id": int_id_${number},"subject_number": "RT0001","subject_status": "T","randomization_date": "01Jan2017", "treatment_id": "B18VP2"} ]} 
    Create Session sw3 ${ENVIRONMENT_TO_RUN_AGAINST} debug=3 
    ${resp}= Post Request sw3 ${ENVIRONMENT_TO_RUN_AGAINST}/api/v1/test1/patients \ ... Content-Type:application/json \ ... Authorization:authkey02 Accept=application/json \ ... data=${data}
    

    Giving error as follows

    Creating keyword failed: No keyword with name '{"patients": [ new "sponsor": "test1", "protocol": "Blue18-B18VP1","site_number": "1001","integration_id": int_id_${number},"subject_number": "RT0001","subject_status": "T","randomization_date": "01Jan2017", "treatment_id": "B18VP2"} ]}' found.

    This isn't valid JSON, new shouldn't be there. Search for an online JSON validation and check for other issues.

    I know nothing about RobotFramework though so probably not the issue. Should it be passed as a string perhaps?


  • Registered Users, Registered Users 2 Posts: 7,128 ✭✭✭Talisman


    I'm not familiar with Robot Framework but looking at the keywords used on the other lines and the error message it would suggest that you need to use a command to create an object and not simply drop a chunk of JSON on the poor unsuspecting framework.

    Depending on what the language operating behind the framework is you might need to declare a different type to use. Given that the code you have posted is plain olde English I'd guess you're dealing with Python. Python would require you to import a library (import json) in order to handle JSON as it's not available out of the box.

    If it is Python then
    ${data}= {"patients":  ... }
    
    is probably supposed to be something like:
    ${data}= Create Dictionary
    
    Afterwards the dictionary would need to be populated. There may even be a magic instruction like:
    ${data}= Create Dictionary From {"patients":  ... }
    

    This is all speculation on my part so apologies if I'm completely wrong, but it would be best to go read the documentation.


Advertisement