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

How to fetch array values using RESTInstance #50

Closed parthvyas88 closed 5 years ago

parthvyas88 commented 5 years ago

{ "seconds": 0.085585, "status": 200, "body": { "count": 6, "entries": [ { "Category": "Books", "Description": "Bhagavad Gita text", "Auth": "OAuth", "API": "Bhagavad Gita", "Link": "https://bhagavadgita.io/api", "HTTPS": true, "Cors": "yes" }, { "Category": "Books", "Description": "Books published in the Netherlands and Flanders (about 2.5 million), book covers and related data", "Auth": "", "API": "BookNomads", "Link": "https://www.booknomads.com/dev", "HTTPS": true, "Cors": "unknown" }, { "Category": "Books", "Description": "Books", "Auth": "apiKey", "API": "Goodreads", "Link": "https://www.goodreads.com/api", "HTTPS": true, "Cors": "unknown" }, { "Category": "Books", "Description": "Books", "Auth": "OAuth", "API": "Google Books", "Link": "https://developers.google.com/books/", "HTTPS": true, "Cors": "unknown" }, { "Category": "Books", "Description": "Books, book covers and related data", "Auth": "", "API": "Open Library", "Link": "https://openlibrary.org/developers/api", "HTTPS": true, "Cors": "unknown" },] } }

I want to fetch data e.g. below Robot script String response body entries[0] API Bhagavad Gita

asyrjasalo commented 5 years ago

Plain text path:

String  response body entries 0 API     Bhagavad Gita

Note list indices - always start from zero.

JSONPath (one of many possible, remember this helped me initially: http://jsonpath.com/)

String  $[0].API     Bhagavad Gita

Hope this helps to get started.

parthvyas88 commented 5 years ago

Thanks!! I had missed the 0 part. However upon using this syntax, I get the value but still not able to validate

Robot Statement: String response body entries 0 API Bhagvad Gita

Error : 20181129 00:30:25.798 : FAIL : u'Bhagavad Gita' is not one of [u'Bhagvad Gita']

Failed validating u'enum' in schema: {u'enum': [u"'Bhagvad Gita'"], 'type': u'string'}

On instance: u'Bhagavad Gita' Ending test: RESTAPI.PublicApi.Validate Request

asyrjasalo commented 5 years ago

For me it seems you are mistyping the name. 👍