Call Jira API to retrive JSON and store in tiddler

62 views
Skip to first unread message

Sylvain Naudin

unread,
Apr 30, 2020, 7:52:36 AM4/30/20
to TiddlyWikiDev
Hi,

I write here first rather than on the usual list because the theme is rather technical.

I'd like to be able to use Jira's API to retrieve the status of a ticket using the JSON output, and update a tiddler field with this result.

I think I have almost all the tracks at hand, but I don't have the skills to implement them..



1. API Jira

Link to the documentation:

I add this link with a JS function to get what I want:
(last post with version 7):

function getCurrentIssueStatus()
{
var statusname;
var issueKey = JIRA.Issue.getIssueKey();
 AJS
.$.ajax({
 url
: "/rest/api/2/issue/" + issueKey,
 type
: 'get',
 dataType
: 'json',
 async
: false,
 success
: function(data) {
 statusname
= data.fields.status.name;
 
}
 
});
 
return statusname;
}

It's

If I test manually on a URL, for example this one randomly picked out https://issues.apache.org/jira/rest/api/2/issue/ZOOKEEPER-3812?fields=status, I noticed that one must first have visited the home page to get authentication (I don't notice this for the internal instance I'm going to call).


About CORS potential limitation, I've got the next.

2. Cartographie demo

Last year, I had the help of a user to realize a GPS coordinates search function.
The principle, calling an API with an address, retrieving the JSON, and updating the field of a tiddler, is exactly what I want to do here!

We don't have too much news from Jean-Bernard on the FR forum, so I ask for help here :)

His work can be found here: https://github.com/oxydum/cartographie

He wrote this function : $:/.macros/geopoint.js

(function(){
"use strict";
exports
.name = "geopoint";
exports
.params = [ {name: "tiddlername"},{name: "url"},{name: "tag"},{name: "link"}];
exports
.run = function(tiddlername,url,tag,link) {
var url = url || "None";
var tag = tag || "Adresse";
var link = link || "";
var head = "origin:*";
var cors_api = "https://cors-anywhere.herokuapp.com/";
//var cors_api = "https://thingproxy.freeboard.io/fetch/";
//var cors_api = "http://cors.io/?";
//var cors_api = "https://crossorigin.me/";
//var cors_api = "https://cors-proxy.htmldriven.com/?url=";
 
var tiddlername = tiddlername || "None";
$tw
.utils.httpRequest({headers:head, url: cors_api+url, callback: function (error,data){
   
if (error){
    console
.log("ERROR:"+error);
   
}
if (!$tw.wiki.getTiddler(tiddlername)) {
 $tw
.wiki.addTiddler({title:tiddlername, tags:tag, text:data, type: "application/json"});
} else {
// le tiddler existe déjà

}
 
}})
if (link=="") {
 
return;
} else { return "[["+tiddlername+"]]";}

};
})();

in addition with $:/_template_ville.

For information the thread of exchange (in French) during its proceedings: https://forum.tiddlywiki.fr/t/un-tiddlywiki-carto-pour-mlc/580/13?u=sylvain



So here's where I'm now.

Does anyone have time to look at it and guide me?

Thanks,
Sylvain

PMario

unread,
Apr 30, 2020, 9:11:50 AM4/30/20
to tiddly...@googlegroups.com
Hi Sylvain,

It seems the API is able to use TOKENS similar to what we use for the GitHub and the GitLab savers. ...

  • The question is, do you need write access?

Since Jira is not a hosting platform, you are right CORS may be an issue. Having a look at the code above, it seems to me, that you are 100% relying on the integrity of the "cors-anywhere" site, if this is the real code you use. ...

The docs at https://github.com/Rob--W/cors-anywhere says, that this is a demo server with a limited amount of requests allowed. So it's not reliable and also not secure for production usage.

Is there a possibility, that the Jire platform is able to serve a file based TW.html file. So it would be possible to skip the CORS stuff. Do they allow to upload "custom help" pages or something similar, which uses the same domain?

Please read those pages:


So is it possible to provide api-tokens with "read only" access to your users?

If yes, it should be possible to connect to the data points as you described.

have fun!
mario




Sylvain Naudin

unread,
Apr 30, 2020, 2:01:31 PM4/30/20
to TiddlyWikiDev
Hi mario,
Thank for your time,

Le jeudi 30 avril 2020 15:11:50 UTC+2, PMario a écrit :
  • The question is, do you need write access?

No, I don't need to write in Jira. I just want to check on demand in my TW if the status have change, and not have to open the URL (lazy man..^^).

 
Since Jira is not a hosting platform, you are right CORS may be an issue. Having a look at the code above, it seems to me, that you are 100% relying on the integrity of the "cors-anywhere" site, if this is the real code you use. ...

Yes, it's true..

The docs at https://github.com/Rob--W/cors-anywhere says, that this is a demo server with a limited amount of requests allowed. So it's not reliable and also not secure for production usage.

Is there a possibility, that the Jira platform is able to serve a file based TW.html file. So it would be possible to skip the CORS stuff. Do they allow to upload "custom help" pages or something similar, which uses the same domain?


No, I wouldn't have a handle on that setting.. But maybe CORS is not an issue.. (I hope).
 

Please read those pages:


So is it possible to provide api-tokens with "read only" access to your users?

If yes, it should be possible to connect to the data points as you described.


I won't have admin rights on Jira (I'm just a user), but I know on the other hand that access is possible without authentication (like the example of the Jira of the Apache foundation)
 

Sylvain Naudin

unread,
Apr 30, 2020, 2:10:02 PM4/30/20
to TiddlyWikiDev
Just add that I'll be on the same office network, not accessible to outside (so thinking about help of an external CORS site wouldn't help me anyway).

Sylvain Naudin

unread,
Apr 30, 2020, 2:46:24 PM4/30/20
to TiddlyWikiDev


Le jeudi 30 avril 2020 20:10:02 UTC+2, Sylvain Naudin a écrit :
Just add that I'll be on the same office network, not accessible to outside (so thinking about help of an external CORS site wouldn't help me anyway).

I just play to try to modify geopoint.js and call it jirapi.js, and it work to create json tiddler with simple macro addition.

I think it not help me since I realize I can't use this method on local work network.

So my best chance is to manipulate and mix this with tiddler creation I think :

function getCurrentIssueStatus()
{
var statusname;
var issueKey = JIRA.Issue.getIssueKey();
 AJS
.$.ajax({
 url
: "/rest/api/2/issue/" + issueKey,
 type
: 'get',
 dataType
: 'json',
 async
: false,
 success
: function(data) {
 statusname
= data.fields.status.name;
 
}
 
});
 
return statusname;
}

But don't know how.
Reply all
Reply to author
Forward
0 new messages