How to call Jira Service Desk Cloud REST API (create ticket) from Single Page App (JavaScript)

Aleksandar Stefanov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 14, 2019

According to: https://developer.atlassian.com/cloud/jira/service-desk/rest/#authentication

"Authentication for REST API requests
If you are integrating directly with the Jira Service Desk Cloud REST APIs it is recommended to use OAuth authentication method. For implementations with low security requirements, such as scripts and bots, it is also possible to use Basic authentication method."

We have a web application e.g. https://xxx.globetax.com that needs to submit a POST to '//xxx.atlassian.net/rest/servicedeskapi/request' using the following code (basic auth):


var request = {
serviceDeskId: 'xx',
requestTypeId: 'yyy',
requestFieldValues: {
summary: 'Inquiry about Claim #' + zzz,
description: aaa
},
requestParticipants: [bbb]
}

const tok = 'USER:PASS'
const hash = btoa(tok)

const parameters = JSON.stringify(request)

$.ajax({
url: ccc,
type: 'POST',
data: parameters,
contentType: 'application/json',
dataType: 'json',
async: false,
processData: false,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + hash)
}
})
.done(function(json) {
})
.fail(function(jqXHR, textStatus, error) {
})

Is there a way to achieve that from JavaScript / XHR - is there a way to allow our origin (seems the answer is no, if so, what was the intent of the API for the Jira Service Desk Cloud REST API)?

 

1 answer

0 votes
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 23, 2019

Hi @Aleksandar Stefanov ,

 

I might not be the best person to answer this question, however, if the issue is that the origin check fails, you may want to use CORS anywhere:

 

Please review above link and let me know if it helps.

 

Cheers,
Dario

Suggest an answer

Log in or Sign up to answer