Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,506
Community Members
 
Community Events
168
Community Groups

Rest API POST to create an issue, getting 400 bad request (Using Salesforce APEX)

Edited

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);

 

1 answer

1 accepted

0 votes
Answer accepted

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS

Atlassian Community Events