Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Only apps can access this resource for connect app

el_moreno April 10, 2023

I have a Spring Boot app that I created following the instructions here:

https://bitbucket.org/atlassian/atlassian-connect-spring-boot/src/master/


I am able to install that app in my Jira instance and I can see it working, meaning, I can see a Hello World being printed to the screen. I am now trying to use the same app to register for web-hooks:


HttpResponse<JsonNode> response = Unirest.post("https://<my_domain>.atlassian.net/rest/api/2/webhook")
.basicAuth("<my_email>", "<API_Token>")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.body(json)
.asJson();
System.out.println(response.getBody().toPrettyString());

 

However, I get the following error message in response:


{
"errorMessages": [
"Only apps can access this resource."
],
"errors": {}
}


I am following all the correct documentation as far as I know, so I am not sure what the issue is. This is clearly a connect app that I created using the documentation provided. I would really like to avoid to user OAuth if possible. Any help would be greatly appreciated!

1 answer

0 votes
Jared Kells
Contributor
April 10, 2023

That request isn't actually being made as the app by the looks of it, you're using basic auth with an email address and token so from Jira's perspective it's just a request from your user account.

Check out the docs for the springboot sample: https://bitbucket.org/atlassian/atlassian-connect-spring-boot/src/master/

They have a section "Making API Requests to the product as the add-on" which might be what you're looking for.

el_moreno April 12, 2023

@Jared Kells Thank you for the response. I took a look at that section and I am doing exactly as it shows there, and it's still a no go, tbh I am kind of disappointed with the documentation, it is very poor and depending on where you look you get different info, anyway, rant over, here is what I am attempting to do:

atlassianHostRestClients.authenticatedAsAddon().postForObject("https://<my_host>/rest/api/2/webhook", myJson, String.class));

I get an HTTP 400 error saying the JSON is not valid, I don't know why as I am using the JSON specified here. 

I also see in the documentation that the above is deprecated, so I am now trying to use:

atlassianHostRestClients.authenticatedAsAddon(AddonAuthenticationType.OAUTH2).postForObject("https://<my_host>/rest/api/2/webhook", myJson, String.class));

With the above I get:


401 Unauthorized: "{"message":"Client must be authenticated to access this resource.","status-code":401}"


which makes sense since I am not doing anything to authenticate. The question is, how do I authenticate? I have not found a single example to follow. 

What I am trying to do is pretty basic, using atlassian-connect-spring-boot I want to register for web hook, that is all I am trying to do, are there valid examples anywhere? 

 

Thank you in advance!

Jared Kells
Contributor
April 18, 2023

One thing that stands out to me from your example is that you have an absolute URL and you're using AddonAuthenticationType.OAUTH2

https://<my_host>/rest/api/2/webhook

Taking a look at the docs, using absolute URLs deprecated and that authentication type is for Connect on Forge apps. Is that the sort of app you're building?

Normally you would register for webhooks in an application lifecycle event such as AddonInstalledEvent and you would use a relative URL which will automatically go to the correct host.

Is this code running in a lifecycle event?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events