Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,638,566
Community Members
 
Community Events
196
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

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

Suggest an answer

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

Atlassian Community Events