Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to parse API Response

I am trying to parse a response from this API, here . However it says the response type is TestLogListResource . How do I parse this as json?

Code to get response

from __future__ import print_statement
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint

# Configure API key authorization: Authorization
swagger_client.configuration.api_key['Authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# swagger_client.configuration.api_key_prefix['Authorization'] = 'Bearer'

# create an instance of the API class
api_instance = swagger_client.TestlogApi()
project_id = 789 # int | ID of the project
test_run_id = 789 # int | ID of the Test Run
page_size = 100 # int | The result is paginated. By the default, the number of objects in each page is 100 if this is omitted. You can specify your custom number (up to 999) in this parameter (optional) (default to 100)
page = 1 # int | By default the first page is returned but you can specify any page number to retrieve objects (optional) (default to 1)

try: 
    # Gets all Test Logs of a Test Run
    api_response = api_instance.get_test_logs_list(project_id, test_run_id, page_size=page_size, page=page)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling TestlogApi->get_test_logs_list: %s\n" % e)

Sample response.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{'items': [{'actual_exe_time': 0,
            'attachments': None,
            'build_number': None,
            'build_url': None,
            'defects': None,
            'exe_end_date': datetime.datetime(2022, 3, 31, 5, 15, 43, tzinfo=tzoffset(None, 19800)),
            'exe_start_date': datetime.datetime(2022, 3, 29, 5, 5, 43, tzinfo=tzoffset(None, 19800)),
            'id': 250378315,
            'links': [{'href': 'https://xxe.qtestnet.com/api/v3/projects/11xx93/test-runs/128439614/test-logs/250378315',
                       'rel': 'self'},
                      {'href': 'https://xxe.qtestnet.com/api/v3/projects/11xx93/test-cases/50735105?versionId=69533056&showParamIdentifier=false',
                       'rel': 'test-case'},
                      {'href': 'https://demoinstance.qtestnet.com/api/v3/projects/120893/test-logs/250378315/attachments',
                       'rel': 'attachments'}],
            'name': None,
            'note': 'Mark to Steve',
            'planned_exe_time': 0,

>Solution :

The class TestLogListResource has a function to_dict, maybe you just need this function. If you realy need json format, you can then json.dumps.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading