Problem mit dem Exportieren von Zyklus in den CSV -Filetyp in der Zephyr Squad Rest APIPython

Python-Programme
Anonymous
 Problem mit dem Exportieren von Zyklus in den CSV -Filetyp in der Zephyr Squad Rest API

Post by Anonymous »

Befolgtes offizielles Doc:
Zephyr Squad Cloud Restapi (ehemals Zephyr für JIRA) < /p>
Get

Code: Select all

Missing parameter: projectId
[/b] als Antwort aus Zephyr -Kader. Ich verstehe nicht, warum der Parameter von ProjectID fehlt, obwohl ich dies in Parametern von Canonical_Path und aus dem JSON -Zyklus ?
übergeben habe

Code: Select all

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')
Tatsächliches Ergebnis:

Code: Select all

{
"clientMessage": "Missing parameter: projectId",
"errorCode": 151,
"errorType": "ERROR"
}
< /code>
[b] Erwartete Ergebnisse: < /strong>
Antwortstatus sollte 200 sein und die Datei in CSV -Format speichern < /p>
 Komplettes Snippet: [/b] 
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)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post