Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Passing data structures into REST calls

  • 16-03-2017 8: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: 6,289 ✭✭✭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