How to access jira rest api with angular js service(http)?

2,369 views
Skip to first unread message

Alok Kumar Singh

unread,
Feb 19, 2016, 3:45:20 AM2/19/16
to Atlassian Connect Dev
I have written this service to get all the projects in JIRA  but it is hitting localhost:3000 where my app is running. What should be the cortrect approach.

(function(){
 
    var projectService = function($http){
 
        var getUsers = function(project){
            console.log()
            return $http.get("/rest/api/2/project")
                .then(function(response){
 
                    console.log(response);
                    console.log(response.data);
                    return response.data;
                });
        };
 
        return {
            get: projectKeys
        };
 
    };
 
    var module = angular.module("postExample");
    module.factory("projectService", projectService);
 
}());

Tobias Anstett (K15t Software)

unread,
Feb 19, 2016, 6:01:04 AM2/19/16
to atlassian-...@googlegroups.com
This documentation page might help you  https://developer.atlassian.com/static/connect/docs/latest/javascript/module-request.html

All request you want to do on any JIRA REST APIs must be executed using the AP bridge respectively AP.request

Cheers,
Tobias

--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vitaliy Zurian

unread,
Feb 19, 2016, 4:48:20 PM2/19/16
to Atlassian Connect Dev
Here's how I do it

Define your service. Make sure you use $timeout to refresh the scope

app.factory('jira', function ($timeout) {
   
return {
        project
: function (success, error) {
            AP
.require('request', function (request) {
                request
({
                    url
: '/rest/api/2/project',
                    success
: function (responseText) {
                        $timeout
(function () {
                            success
(JSON.parse(responseText));
                       
}, 0);
                   
},
                    error
: function () {
                        $timeout
(function () {
                            error
();
                       
}, 0);
                   
}
               
});
           
});
       
},
   
}
});


Then inject "jira" service into your controller or whatever, and use it:

var success = function (project) {...};
var error = function () {...};



jira.project(success, error);


Hope it helps,
Vit

On Friday, February 19, 2016 at 9:45:20 AM UTC+1, Alok Kumar Singh wrote:
I have written this service to get all the projects in JIRA  but it is hitting localhost:3000 where my app is running. What should be the cortrect approach.

(function(){
 
    var projectService = function($http){
 
        var getUsers = function(project){
            console.log()
            return $http.get("/rest/api/2/project")
                .then(function(response){
 
                    console.log(response);
                    console.log(response.data);
                    return response.data;
                });
        };
 
        return {
            get: projectKeys
        };
 
    };
...

Robert Massaioli

unread,
Feb 20, 2016, 1:17:57 AM2/20/16
to Atlassian Connect Dev
Question also asked here: https://answers.atlassian.com/questions/37029849/how-to-access-jira-rest-api-with-angular-js-servicehttp

Please restrict yourself to asking questions in only one location; and only if you get no response there then move to the other location. Cheers. :)


On Friday, 19 February 2016 19:45:20 UTC+11, Alok Kumar Singh wrote:
I have written this service to get all the projects in JIRA  but it is hitting localhost:3000 where my app is running. What should be the cortrect approach.

(function(){
 
    var projectService = function($http){
 
        var getUsers = function(project){
            console.log()
            return $http.get("/rest/api/2/project")
                .then(function(response){
 
                    console.log(response);
                    console.log(response.data);
                    return response.data;
                });
        };
 
        return {
            get: projectKeys
        };
 
    };
...
Reply all
Reply to author
Forward
0 new messages