Contributions
Issue with Exporting Cycle into CSV filetype in Zephyr Squad REST API
Followed Official Doc: Zephyr Squad Cloud REST API (formerly Zephyr for Jira) GettingMissing parameter: projectIdas a response from Zephyr Squad. I am not getting why parameter of projectId is missing even though I have been passing this in parameters of CANONICAL_PATH and in Json cycle...? RELATIVE_PATH = '/public/rest/api/1.0/cycle/{}/export'.format(cycle_id) CANONICAL_PATH = 'GET&' +RELATIVE_PATH +'&' + 'projectId=' + str('10000') + '&versionId=' + str('10000') + '&exportType=' + str('CSV') Actual Result: <Response [400]> { "clientMessage": "Missing parameter: projectId", "errorCode": 151, "errorType": "ERROR" } Expected Result: Response status should be 200 and save the file into CSV format Complete Snippet: import json import jwt import time import hashlib import requests def is_json(data): try: json.loads(data) except ValueError: return False return True # USER ACCOUNT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' # ACCESS KEY from navigation >> Tests >> API Keys ACCESS_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # ACCESS KEY from navigation >> Tests >> API Keys SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # JWT EXPIRE how long token been to be active? 3600 == 1 hour JWT_EXPIRE = 3600 # BASE URL for Zephyr for Jira Cloud BASE_URL = 'https://prod-api.zephyr4jiracloud.com/connect' # RELATIVE PATH for token generation and make request to api cycle_id = 'ca55798e-e9e8-4ebb-8b43-efac9360e615' RELATIVE_PATH = '/public/rest/api/1.0/cycle/{}/export'.format(cycle_id) CANONICAL_PATH = 'GET&/public/rest/api/1.0/cycle/' + cycle_id + '/export?' + 'projectId=' + str('10000') + '&versionId=' + str('10000') + '&exportType=' + str('CSV') # TOKEN HEADER: to generate jwt token payload_token = { 'sub': ACCOUNT_ID, 'qsh': hashlib.sha256(CANONICAL_PATH.encode('utf-8')).hexdigest(), 'iss': ACCESS_KEY, 'exp': int(time.time())+JWT_EXPIRE, 'iat': int(time.time()) } # GENERATE TOKEN token = jwt.encode(payload_token, SECRET_KEY, algorithm='HS256').strip() # REQUEST HEADER: to authenticate and authorize api headers = { 'Authorization': 'JWT '+token, 'Content-Type': 'application/json', 'zapiAccessKey': ACCESS_KEY } # REQUEST PAYLOAD: to create cycle cycle = { 'versionId': 10000, 'projectId': 10000, 'exportType': 'CSV', 'folderId': 'UI' } # MAKE REQUEST: raw_result = requests.get(BASE_URL + RELATIVE_PATH, headers=headers, json=cycle) print(raw_result) # Download the CSV file and save it to disk with open("Export.csv", "w", newline="") as csvfile: csvfile.write(raw_result.text) if is_json(raw_result.text): # JSON RESPONSE: convert response to JSON json_result = json.loads(raw_result.text) # PRINT RESPONSE: pretty print with 4 indent print(json.dumps(json_result, indent=4, sort_keys=True)) else: print(raw_result.text)333Views0likes0CommentsError Code: 137 | Exporting executions download | We have encountered with some minor issue
The below snippets returned with 200 status code containing the Execution Id <Response [200]> 0001677994347309-242ac113-0001 BASE_URL = 'https://prod-api.zephyr4jiracloud.com/connect' # RELATIVE PATH for token generation and make request to api RELATIVE_PATH = '/public/rest/api/1.0/executions/export' CANONICAL_PATH = 'POST&'+RELATIVE_PATH+'&' After passing Execution ID to API '/public/rest/api/1.0/executions/export/download/' Getting <Response [500]> { "clientMessage": "We have encountered with some minor issue. Please try again.", "errorCode": 137, "errorType": "ERROR" } Complete Snippets: import json import jwt import time import hashlib import requests def is_json(data): try: json.loads(data) except ValueError: return False return True # USER ACCOUNT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' # ACCESS KEY from navigation >> Tests >> API Keys ACCESS_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # ACCESS KEY from navigation >> Tests >> API Keys SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # JWT EXPIRE how long token been to be active? 3600 == 1 hour JWT_EXPIRE = 3600 # BASE URL for Zephyr for Jira Cloud BASE_URL = 'https://prod-api.zephyr4jiracloud.com/connect' fileName = '0001677994347309-242ac113-0001' # RELATIVE PATH for token generation and make request to api RELATIVE_PATH = '/public/rest/api/1.0/executions/export/download/' + fileName CANONICAL_PATH = 'GET&'+RELATIVE_PATH+'&' # TOKEN HEADER: to generate jwt token payload_token = { 'sub': ACCOUNT_ID, 'qsh': hashlib.sha256(CANONICAL_PATH.encode('utf-8')).hexdigest(), 'iss': ACCESS_KEY, 'exp': int(time.time())+JWT_EXPIRE, 'iat': int(time.time()) } # GENERATE TOKEN token = jwt.encode(payload_token, SECRET_KEY, algorithm='HS256').strip() #.decode('utf-8') # REQUEST HEADER: to authenticate and authorize api headers = { 'Authorization': 'JWT '+token, 'Content-Type': 'application/json', 'zapiAccessKey': ACCESS_KEY } cycle = { 'fileName': '0001677994347309-242ac113-0001' } # MAKE REQUEST: raw_result = requests.get(BASE_URL + RELATIVE_PATH, headers=headers, json=cycle) print(raw_result)324Views0likes0Comments