how to get JSON data from an API in robot framework - selenium

I am trying to get JSON data from an API in robot framework which has data with id's. I have to get the count of id's present in the data obtained from the API.
I have tried the below code:
${result} = get ${API_JSON_PATH}
Should Be Equal ${result.status_code} ${200}
${json_data} = Set Variable ${result.content}
Log ${json_data}
I am getting the below mentioned error:
No keyword with name '${result} = get' found.
Is the approach correct or is there any other better ways for getting the JSONS data?

I'm using the RequestsLibrary and it's slide different from what you are doing.
the credential are not needed in your case but this is the example:
#{credential}= Create List Your_Username Your_Password
Create Session YOUR_API_ALIAS YOUR URL auth=#{credential}
${api}= Get Request YOUR_API_ALIAS YOUR_URI
if you want get the content of the JSON:
${api.json()}
Documentation: https://bulkan.github.io/robotframework-requests/

You need to have two or more spaces after the =. Robot looks for two or more spaces to find keywords and arguments, so it thinks your first statement begins with the keyword ${result} = get. Since that's not a valid keyword, you get that error.

Related

Formulating REST API call

Here is my query string
https://api.meetup.com/2/open_events?country=us&state=ca&city=sanfrancisco&category=34&page=10&group_photo&sign=true&&sign=true
I'm having no success reaching the group_photo resource.
In the docs they say:
group_photo
Returned when fields request parameter contains "group_photo".
Represents photo for the group hosting the event
I tried changing group_photo to group_photo=true but that didn't help.
Here's the console if you wanna test it
From the Meetup API documentation:
fields: Request that additional fields (separated by commas) be
included in the output
and
group_photo: Returned when fields request parameter contains
"group_photo". Represents photo for the group hosting the event
so you must add fields=group_photo and the call you gave above would be be something like:
https://api.meetup.com/2/open_events?country=us&state=ca&city=sanfrancisco&category=34&page=10&fields=group_photo&sign=true&sign=true

Softlayer API: filter image by OS referenceCode

I am trying to filter out my list of images by OS reference code. Here is the url I am trying:
https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups.json?objectMask=mask[flexImageFlag]&objectFilter={'children': {'blockDevices': {'diskImage': {'softwareReferences': {'softwareDescription': {'referenceCode': {'operation': 'REDHAT_6_64'}}}}}}}
But I am kept getting the following error msg:
{"error":"Unable to parse object filter.","code":"SoftLayer_Exception_Public"}
Can anyone help me see what is wrong? Thanks in advance!
Q.Z.
The filter is wrong, but in my tests the filter is not working with the "referenceCode" property; you need to use another property such as name, version or both. See below the examples:
using name and version property
https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=mask[flexImageFlag]&objectFilter={"blockDeviceTemplateGroups": {"children":{"blockDevices":{"diskImage":{"softwareReferences":{"softwareDescription":{"name":{"operation":"CentOS"}, "version":{"operation":"6.3-32"}}}}}}}}
Using only a property (name in this case)
https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=mask[flexImageFlag]&objectFilter={"blockDeviceTemplateGroups": {"children":{"blockDevices":{"diskImage":{"softwareReferences":{"softwareDescription":{"name":{"operation":"CentOS"}}}}}}}}
Regards
Looks like you are using the REST api. The example in the
API reference, suggests that this parameter should be in JSON format:
https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,hostname]&objectFilter={"datacenter":{"name":{"operation":"dal05"}}}
Your error says "Unable to parse object filter.", so the error is probably just be that your parameter is invalid JSON: The JSON standard only accepts double quotes.
Try replacing
{'children': {'blockDevices': {'diskImage': {'softwareReferences': {'softwareDescription': {'referenceCode': {'operation': 'REDHAT_6_64'}}}}}}}
with the corresponding valid json:
{"children": {"blockDevices": {"diskImage": {"softwareReferences": {"softwareDescription": {"referenceCode": {"operation": "REDHAT_6_64"}}}}}}}

id value not returned in response to select query as specified

Using the new OneDrive API as described on the GitHub page, by the following statement:
GET /drive/root/children?select=name,size
By submitting the request with the select=name,size query string,
the objects in the response will only have those property values
included. However, by default, the id value will always be returned
even if its not specified.
Still the problem is id is not returning in response by default (as claimed above on GitHub page), only those properties that are mention in select query is return in response.
Looks like a bug in our docs. Thanks for pointing it out! This is expected behavior. When you provide a 'select' statement the API will only return the properties you ask for.
I was also able to reproduce this and the "id" is not returned. It is returned when you include it in the query. (i.e. drive/root/children?select=id, name, size).

Best way to get a return tag from a sql SELECT command

I making a virtual assistant client for my University project and there is a slight problem in getting a tag return based on match string.
The system works like this:
1. The user speech input is converted into a string.
2. The string is then matched to column in table.
3. The matching column returns its id which then return two tags from another table.
The problem is for calling someone, how should I go around it?
I mean, the user will say something like this: "Call Arya", here I can't have predefined command for each person so I have to use "MATCH" or "LIKE" selectors in SQL.
But then if I use these selectors then it will return me the tag for say opening facebook app even if I just "facebook", as the commands for facebook will be "open facebook" or "run facebook".
So how to work around it. Please help.

Get Test Sets in an Iteration with REST api

I am working with the Rally REST API's, version 3 beta.
How do you to get the list of Test Sets in a particular Iteration?
For other entities I'm working on, I am finding it easy to navigate the tree as there is a URL to the collection as part of the parent. Test Sets appear under an Iteration in the UI but do not seem to fit anywhere in the object graph in the web services.
This is as far as I got:
https://rally1.rallydev.com/slm/webservice/v3.0/testset
?workspace=<workspace ref>
&project=<project ref>
&query=(Iteration.Name="Sprint 82")
But it gives an error: Could not parse: Unknown operator ")"
If I remove the parenthesis, it can't parse the expression.
Try putting spaces around the = operator:
query=(Iteration.Name = "Sprint 82")