I was able to get the Rest API to GET issues working and get a response of all issues. I am trying to do a POST and create an issue and keep getting 400 bad request. I can't see an error in the json string for the body.
Here is the Salesforce Apex code:
// trying POST to create issue
stringData = '{"update": {}, "fields" : {"project" : {"key" : "IMWW"},"issueType":{"name":"Task"}, "summary" : "Rest test from SF", "description" : "new description from SF to Jira API"}}';
http = new Http();
request = new HttpRequest();
request.setHeader('Content-Type', 'application/json');
request.setHeader('Accept', 'application/json');
request.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(pwBase64) );
request.setEndpoint('https://<mydomain>.atlassian.net/rest/api/latest/issue');
request.setBody(stringData);
request.setMethod('POST');
response = http.send(request);
I added a Sytem.bebug('responseBody=' + response.getBody() ); to my code to get a little more detail.
Despite seeing examples for the json for the issueType as:
"issueType":{"name":"Task"}
This was the incorrect syntax. Two things I had to correct. issueType must be all lower case as "issuetype" and had to use "id" : <actual issuetype id value>
The correct json format for my test create issue should look like:
stringData = '{ "fields" : {"project" : {"key" : "IMWW"},"issuetype":{"id":"10004"}, "summary" : "Rest test from SF", "reporter":{"id":"5f3ecef6fcaf93003bc95ca6"} }}';
The issuetype keyword must be lowercase. I missed this initially. You can provide the issuetype "id" or the "name". Once i corrected and used "issuetype", I could use {"name":"Task"} too.
Also need to include the "reporter" "id" as well.
Hope this helps someone else.
-Mike
Hi @Mike Schumacher ! I am having your same issue. The only blockers I have is.. how di I get my reporter id?
Is there an easy way through the website?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From my experience now (2024), the only fields that are required are project, issue type, and summary. Here is a working Javascript example extended from @Mike Schumacher's helpful answer:
const body = {
"fields": {
"project": {
"key": "ssss",
},
"issuetype": {
"name": "Task"
},
"summary": "Rest test from SF"
}
}
try {
const response = await fetch(..., {
method: 'POST',
headers: {
},
body: JSON.stringify(body)
}
...
} catch ...
"ssss" is the name of the project. And the issuetype name MUST match an existing issue type. This was the issue that burned me for a while. I was using "Service request" - which kept failing, until I finally realized that in my case, it needed to be "[System] Service request".
Using the "Task" issue type, thanks to the example above, is what led me to the realization that my 400 error was caused by an inaccurate issue type. And I suspect "Task" is a valid issue type across all Jira instances.
Lastly, while it's not required, if you do want to include the reporter id, you can find it as follows:
I hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.