How to store add-on properties on JIRA cloud using REST Api Edited

I currently working on JIRA cloud addon. I want to store my addon properties on JIRA cloud by using REST apis. I refered this tutorial https://developer.atlassian.com/cloud/jira/platform/storing-data-without-a-database/.

 According to this for saving the properties, I used this REST call

Request :

PUT 

/rest/atlassian-connect/1/addons/<addon_key>/properties/<property_key>

 Response :

{
"status-code": 404,
"message": "Add-on with key does not exist."
}

 Could you please give me a solution to fix this or is there any other way to store add-on properties on JIRA cloud.

 

2 answers

Although the answer "Add-on with key does not exist." points to a wrong add-on key, in my case the problem was the context. As the app-properties-api documentation sais

Request issued by a user with insufficient credentials, e.g. for an app's data by anyone but the app itself, or for a app that does not exist.

Where the interesting part in my case was "for an app's data by anyone but the app itself" meaning that the requests have to be send within the app (a simple GET request from the browser will fail with the given error)

I had to send the request from within the app (index.js). First a PUT and then a GET for the property

app.get('/store', addon.authenticate(), function (req, res) {
var userKey = req.query['user_key'];
var clientKey = req.context.clientKey;

var options = {
headers: {
'X-Atlassian-Token': 'nocheck'
},
url: '/rest/atlassian-connect/1/addons/<add-on-key>/properties/<property-key>',
json: 'true'
};

getHTTPClient(clientKey, userKey).put(options,
function (err, response, contents) {
getHTTPClient(clientKey, userKey).get(
'/rest/atlassian-connect/1/addons/<add-on-key>/properties/<property-key>',
function (err, response, contents) {
contents = JSON.parse(contents);
res.render('test', {
'test': contents,
'status': response.statusCode
});
});
});
});

function getHTTPClient(clientKey, userKey) {
return addon.httpClient({
clientKey: clientKey,
userKey: userKey,
appKey: addon.key
});
}

This just a simple example and not meatn for production :)

I can confirm this analysis: such requests can only be done programmatically from within the application. Requests sent from a browser will not work.

This answer should be marked as solution.

0 vote
Stephen Deutsch Community Champion Jul 25, 2017

It sounds like the add-on key is not correct. Check your atlassian-connect.json file again and make sure that it matches the key there exactly. Everything else seems to be correct.

I checkd the key. It is correct. And again i check this call. I got success responce.

GET


/rest/atlassian-connect/1/addons/<addon_key>

 In here i used basic auth and i authenticated as host user. Do i need to authenticated  as addon. 

@Tharanga,

Were you able to fix this issue ?

I'm having the exact same issue.

Thanks.

Any news on this?

I encountered the same problem. However, I authenticated with

AtlassianHostRestClients.authenticatedAsAddon()

from my plugin.

Thanks.

Update:

I did the call above via Firefox REST Plugin while logged in.

When doing the same thing programmatically in my plugin I see the following in my log:

PUT request for "https://kuespert-dev.atlassian.net/rest/atlassian-connect/1/addons/<plugin-key>/properties/testProperty" resulted in 201 (Created)

Created GET request for "https://kuespert-dev.atlassian.net/rest/atlassian-connect/1/addons/<plugin-key>/properties/testProperty"

GET request for "https://kuespert-dev.atlassian.net/rest/atlassian-connect/1/addons/<plugin-key>/properties/testProperty" resulted in 200 (OK)

But the values are all null

Sorry, didn't document the Firefox REST call:

URL:

https://kuespert-dev.atlassian.net/rest/atlassian-connect/1/addons/com.xqual.jira.jira-xstudio-connect-plugin/properties/testProperty?jsonValue=true

Headers:

Content-Type: application/json

And being logged in in another browser tab in Jira/Cloud.

Result:

{

  "status-code": 404,

   "message": "Add-on with key does not exist."

}

I've got the sample problem... did anyone find an answer?

For me it's now working - I had a problem parsing the returned Json. But it's only working programmatically - not when called via the Firefox Rest client in the browser.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jun 14, 2018 in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

496 views 2 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you