I am trying to create a test issue using REST API. I am doing in python.
However I am getting 400 error saying bad request.Can you please correct if
something is incorrect.
Here is the python code.
rom urllib2 import Request, urlopen
from json import dumps, load
from base64 import b64encode
def createIssue():
# Variables used:
# 'username' and 'password' variables for encoding into header below
username = 'snayani@threatmetrix.com'
password = 'test'
# New Test Issue Variables:
issueProjectKey = "QA"
issueSummary = "Login Service Test"
issueDescription = "Login Credential Combination Test"
issueTypeName = "Test"
# 'baseURL' holds basic data for JIRA server that will be used in API calls
# 'createTestIssueURL' hold URL sent to JIRA to create a new Issue
# 'createTestStepURL' hold URL sent to ZAPI to add a test step to a Test issue
baseURL = 'https://jira.sac.int.threatmetrix.com'
createTestIssueURL = baseURL + "/rest/api/2/issue/"
# 'headers' holds information to be sent with the JSON data set
# Initialized with Auth and Content-Type data
# Authorization header uses base64 encoded username and password string
headers = {"Authorization": " Basic " + b64encode(username + ":" + password), "Content-Type": "application/json"}
# ///// Create Test Issue /////
# Create a new Zephyr for JIRA Test issue in specified project
print "Creating Test Issue..."
newTestValues = dumps({
"fields": {
"project": {
"key": issueProjectKey
},
"summary": issueSummary,
"description": issueDescription,
"issuetype": {
"name": issueTypeName
}
}
})
request = Request(createTestIssueURL, data=newTestValues, headers=headers)
js_res = urlopen(request)
newTestId = objResponse['id']
print "Test Issue Created! New ID is: " + newTestId
if __name__ == "__main__":
createIssue()