Hi all,
I need to create an Jira issue by using REST API. I am trying to use UTL_HTTP package of ORACLE to post a HTTP request as follows:
DECLARE
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'NAME/rest/api/3/issue';
name varchar2(4000);
buffer varchar2(4000);
content varchar2(4000) := '{
"update": {},
"fields": {
"summary": "Yapilmasi gereken isler",
"issuetype": {
"id": "10003"
},
"project": {
"id": "10000"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Is atamalari yapildi!!!",
"type": "text"
}]}]},
"reporter": {
"id": "5e9054cbacb63e0b8355a467"
},
"labels": [
"bugfix",
"blitz_test"
],
"assignee": {
"id": "5e9054cbacb63e0b8355a467"
}
}
} ';
begin
req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
utl_http.set_header(req, 'Content-Type', 'application/json');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.set_header(req, 'Authorization', 'Basic C3xCPF0cFJaEUW48nqUsAEAC');
utl_http.write_text(req, content);
res := utl_http.get_response(req);
-- process the response from the HTTP call
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffer);
end loop;
utl_http.end_response(res);
exception
when utl_http.end_of_body
then
utl_http.end_response(res);
end;
end ;
I get 'PL/SQL procedure successfully completed.' result however issue is not created.
Can somebody help me?
Hi,
I understand that you are wanting to be able to create an issue in Jira via REST when called from Oracle's PLSQL. It seems like this is possible with the utl_http package, but I have to admit I haven't used this particular REST client before. I am pretty confident though in using Jira's REST API with other clients.
I'm also confused about this question because it is tagged with a jira-server tag, but your REST syntax seems to be very much based on the Jira Cloud REST API reference. It is important for us to understand if this is Jira Cloud or Jira Server because the REST APIs are slightly different in regards to versions, and means of authentication. If you happen to be using Jira Server, then you should be aware that Jira Server is still using the v2 REST endpoints and is not using the v3 like Jira Cloud is right now.
The other problem here is that your client might not be listening for the response that Jira is providing. For most endpoints like this, Jira will provide a response in json format regardless of whether or not the request was successful. Many clients listen for this, such as curl for example, but if your client isn't setup to listen for this response, it likely explains why the commands run, but you don't see any new issue in Jira. I suspect that something failed in the request, and that response is really needed for us to understand what the real problem here is.
Regardless of which platform of Jira this is (Cloud or Server), I would recommend that you adjust the headers of your request. I have seen Jira be rather picky about the headers that get included in a REST call. Having the wrong headers, or extra headers can produce unexpected results. Looking at the Create issue endpoint, it provides the example headers to use with curl of
--header 'Accept: application/json' \ --header 'Content-Type: application/json' \
In your example, I'd drop the 'user-agent' and 'Content-Length' headers entirely to start, and then make sure that you have the 'Accept: application/json' as a header here specifically for creating issues on this endpoint (not all REST endpoints in Jira require that header). If you're using Jira Cloud, then that authorization header should be fine here.
I would also recommend shortening your request to remove some of these elements. For example, the reporter field is not always something you can define during issue creation in Jira anyways. I know that our examples show it there, but in many cases the user creating the request is defaulting to be the reporter. It's possible that field could be preventing this request from going through.
Ideally, I would want to see the exact response that Jira provides you when making a REST call like this. Success or failure, Jira is providing a json payload in response to receiving this request. It would be great if we can see that response to better understand the error that Jira is having with the request. However it's not clear to me exactly how to setup this Oracle tool in order to make it display this response. If you can't get this tool to show that response, it might be worth just trying to use curl to make the same kind of call, complete with the same headers, in order to see what response you get back from Jira.
I hope this helps, please let me know the results.
Andy
Hi @Andy Heinzer ,
Thank you for your answer. It is very helpful.
First, I tried on Jira Cloud by UTL_HTTP package of Oracle and Python separately. I was able to create an issue.
However, my primary job is to use Jira Rest API on JIRA Server. I started to try by using Python. On Jira Cloud I have used HTTPBasicAuthor method and it takes e_mail and API Token inputs and it works. However, on Jira Server firstly I tried the code below on command window:
curl -H "Authorization: Basic <API TOKEN>" -X GET -H "Content-Type: application/json" http://hostname:8080/rest/api/2/issue/createmeta
While this curl code works, HTTPBasicAuthor method of Python does not work.
I wonder, on Jira server, which inputs the HTTPBasicAuthor method takes.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ozan,
Glad that was helpful. While Jira Cloud will provide all users the ability to create their own API Token, Jira Server does not do this natively. As such the basic auth that Jira Server's REST API will use is just expecting the username and password.
But if you are supplying this auth in a header, then you have to first build a string of
username:password
And then base64 encode that string, and then pass that string in the header, such as
curl -H "Authorization: Basic ZnJlZDpmcmVk"
If you're on a linux/unix machine you can do this with a command such as
echo -n username:password | base64
Or a Windows machine could use a powershell terminal to run
$Text = ‘username:password’ $Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text) $EncodedText = [Convert]::ToBase64String($Bytes) $EncodedText
in order to get that string needed.
Try that and let me know if that helps.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andy,
Yes I encode my user name and password.
curl -H "Authorization: Basic ZnJlZDpmcmVk"
This command worked.
However, on Python, like on cloud version HTTPBasicAuth("<e_mail>","<API_TOKEN>") does not work with the API TOKEN above. It works if a use HTTPBasicAuth("<user_name>","<password>") but I need to use the API TOKEN because of the security issues.
Ozan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ozan,
As @Andy Heinzer mentioned, Jira server expects username:password
Unfortunately, basic auth via tokens is not supported yet in Server and Data Center installation.
At the moment it's possible only via 3rd party plugins.
You can give a try to API Tokens for Jira that I've developed.
Regards, Roman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Roman,
curl -H "Authorization: Basic ZnJlZDpmcmVk"
Because this command works, I understand that basic auth via tokens is supported in Jira Server. Am I not right?
Regards, Ozan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Basic auth fully supported in Jira Server.
And this is one of the ways how scripts connects to REST API.
However, you can use there only username:password pairs (fred:fred) and no ability to substitute password with a token (fred:H16gOI61Gaw1Hm7lQ3kP).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.