Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Facing problem in authenticating REST request in my node js jira plugin

ajay yadav August 7, 2016

Hi,

I am facing problem in accessing JIRA rest API. It tells me that I don't have permission to view this issue, but I do have the access.

 Here is a peak in my code & node console.

 

1.png2.png

 

Below is atlassian-connect.json

image2016-8-8 11:57:28.png

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 8, 2016

You should NOT add any basic auth headers for you add-on requests. This is against the policy for Marketplace add-ons and it is simply not needed.

You are most likely running into this issue, which was recently fixed https://ecosystem.atlassian.net/browse/ACEJS-21. The fix is in a new beta release of ACE, version 1.1.0-beta.3.

You can work around this problem by changing your code to not reference the absolute URL for the JIRA instance (which is a bad practice anyway, since your add-on can be installed into multiple JIRA instances):

request({
    // url: 'http://mirketa:2990/jira/rest/api/2/issue/VTP-3' <-- this is wrong
    url: '/rest/api/2/issue/VTP-3',
    method: 'PUT'
})

Furthermore, running a JIRA instance locally is no longer supported and you will probably run into problems. Please see our announcement for details on how to migrate: https://developer.atlassian.com/blog/2016/04/cloud-ecosystem-dev-env/

Thanks

ajay yadav August 8, 2016

That sounds logical . Thanks @Seb Ruiz

ajay yadav August 9, 2016

@Seb Ruiz: I did all the set up now - registered for new cloud instance - installed my plugin there. I am still not able to update the issue.

It says :  [Error: Invalid URI "/rest/api/2/issue/VTP-3"] - this is when I am using request module.

Code is same:

request({
                    // To Do
                    url: '/rest/api/2/issue/VTP-3', //URL to hit
                    method: 'PUT',
                    //Lets post the following key/values as form
                    json: {
							"fields":
							{
								"summary":"test 3091"
								
							}
						}
                }, function(error, response, body) {
                    if (error) {
                        console.log(error);
                    } else {
                        console.log(response.statusCode, body);
                    }
                });

 

I have also tried to do it in another way using httpClient. I have successfully got a response on "GET" request but "PUT" request gives a 403 status. I am unable to understand why happened so? It is actually strange to me, why Jira gave a 403 status on PUT & not on GET request?

 

var httpClient = addon.httpClient(req);
httpClient.put({
url: '/rest/api/2/issue/VTP-3',
json: {

"fields":
{
"summary":"test 309"

}
}
}, function(err, httpResponse, body){
console.log('body.length=',body.length);
console.log('httpResponse.body ==== ',httpResponse.body);
console.log("I did it");
});
seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2016

In your first example, you are using the generic request module. You are correct to use addon.httpClient(req) to instantiate the request module that ACE extends. You can read more about this in the README.

The new 403 error you are getting is because your add-on has only requested the READ scope, which means it is not permitted to create or update issues. In our documentation you can read more about scopes.

ajay yadav August 9, 2016

@Seb Ruiz : Where can I set the scope in my request or addon?

ajay yadav August 9, 2016

@Seb Ruiz: I was able to do it. Thanks. I don't know why I wasn't able to find this documentation which you people have already put on the web. Thanks again !!!

ajay yadav August 9, 2016

Hi @Seb Ruiz, If you can provide the documentation of the custom module that extends ACE. Not the README link, but apart from this. For example, I want to find out what all properties are available to "addon" variable & like this to "req" & "res" variables? Do you guys provide any documentation to this?

seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2016

We do not provide this level of detail - but you are welcome to look at the source code.

https://bitbucket.org/atlassian/atlassian-connect-express/src

0 votes
Siegfried Huber August 8, 2016

Hi

You have to add a header to your POST/PUT request.

The header looks like:

Authorization: Basic <base64-encoded user pwd>

 

Greetings

Sigi

ajay yadav August 8, 2016

can you show me how to add it?

request({
                    // To Do
                    url: 'http://mirketa:2990/jira/rest/api/2/issue/VTP-3', //URL to hit
                    method: 'PUT',
					authorization: "Basic YWRtaW46YWRtaW4=",
                    //Lets post the following key/values as form
                    json: {
							"fields":
							{
								"customfield_10303":"2016-08-03T17:28:00.639+0530"
								
							}
						}
                }, function(error, response, body) {
                    if (error) {
                        console.log(error);
                    } else {
                        console.log(response.statusCode, body);
                    }
                });

Is this the right way that I have added? I tried this but it is not working .

Siegfried Huber August 8, 2016

Hi

I just checked my code: the header for Username test and Pwd test123 is

Authorization: Basic base64(Username + ":" + Pwd), which is

Authorization: Basic dGVzdDp0ZXN0MTIz

I hope this will help.

 

TAGS
AUG Leaders

Atlassian Community Events