Create issue in JIRA Cloud using REST API

Hello,

I’m having trouble creating a new issue in JIRA Cloud using the REST API. I have an Atlassian Connect Express app that is able to successfully execute GET /rest/api/2/search and GET /rest/api/2/project. However, POST /rest/api/2/issue doesn’t work; I got a 403 Forbidden response. The scope is set to “write” in atlassian-connect.json.

I am able to create new issues using HTTPie -
http POST https://mydomain.atlassian.net/rest/api/2/issue --auth username:password < new_issue.json.

Any ideas?

Thanks!
John

It might be because there are fields that are required to have values and you are not providing values for them. Check the result of GETing /rest/api/2/issue/createmeta resource.

1 Like

Thanks David. The only required field is the issuetype, which I am providing. Also, I’m using the same json in the HTTPie and javascript versions of the call. So, I don’t think it’s a missing required field.

In the response I’m getting a “[Simple-XDM] Failed to validate origin: https://johngturk.atlassian.net” message. The javascript is executing on the client side. Is this a cross-origin issue?

Thanks,
John

Sounds like it might be, John. Are you using AP.Request? If not, that’ll be the trouble.

Hey David, I am using AP.Request. Here’s my code:

    AP.require('request', function(request) {
        request({
            url: '/rest/api/2/issue',
            type: 'POST',
            contentType: 'application/json',
            data: {
				"fields": {
					"project": {
						"key": "TEST"
					},
					"summary": "I just created a new issue!",
					"issuetype": {
						"name": "Task"
					}
				}
            },
            success: function (response) {
		        console.log("success")              
            },
            error: function (response) {
            	console.log("error")
            }
        });        
    });

Try stringifying the data. Here’s an example from my code of POSTing to issuetype.

AP.require('request', function(request) {
    request({
        url: '/rest/api/2/issuetype',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({
            name: args.name,
            description: args.description,
            type: 'standard'
        }),
        success: function(text) {
            ...
        },
        error: function(xhr, statusText) {
            ...
        }
    });
});

Thanks David. I gave that a try but I’m still getting the “Failed to validate origin” error. I even tried creating a new issue type based on your code and got the same error. The domain is “https://johngturk.atlassian.net,” which is my developer instance in JIRA Cloud. The Javascript below is running on the client side, so I don’t know why the origin can’t be validated. Thanks for all your help; I really appreciate it.

    AP.require('request', function(request) {

		var data = {
			fields: {
				project: {
					key: "TEST"
				},
				summary: "I just created another issue!",
				issuetype: {
					name: "Task"
				}
			}				
		}

        request({
            url: '/rest/api/2/issue',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function (response) {
				console.log("success")
            },
            error: function (response) {            	
            	console.log("error")
            }
        });        
    });

The cause of this issue ended up being something pretty stupid - I was missing the credentials.json file. Without this file, I was still able to use GET REST methods in the API, but no POST methods.

1 Like

Hi, I know the forum is closed. However, I’m making the same call to the API, with an atlassian-connect-express proyect, using AP.require (the code is the same), I have my credentials.json file, I think if I dont have it, I could not install the addon in my Jira space. Anyway, I have the same problem: [Simple-XDM] Failed to validate origin.

Did you do something with the credentials.json file? In other words, you had some referrence or something like that?

Thanks.

Hey @peloxoo, idk what causes that error for you, but one thing you should be aware is that AP.require is now deprecated, and you should use AP.request directly instead

Credentials file is just for auto install/reinstall process that implemented in ACE, if you wanna try to install your add-on without it being auto installed via that mechanism just delete credentials file and use ngrok url to upload it to your instance, though you might need to run https server instead of http, since only https is allowed for installation

Ok, thank you for the quick response. Well I just realize that it was a simple warning in the console, but I appreciate what you told me about the AP.request. I am now able to do a POST with no problem.
Thank you a lot!