Ask a Question

Issue with Exporting Cycle into CSV filetype in Zephyr Squad REST API

nishanth
New Contributor

Issue with Exporting Cycle into CSV filetype in Zephyr Squad REST API

Followed Official Doc:
Zephyr Squad Cloud REST API (formerly Zephyr for Jira)

Getting Missing parameter: projectId as 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)
 
0 REPLIES 0
cancel
Showing results for 
Search instead for 
Did you mean: