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

Tharanga July 25, 2017

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.

 

3 answers

2 votes
Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
March 7, 2018

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 :)

Matthias Küspert March 9, 2018

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.

mararn1618 _secretbakery.io_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
March 18, 2021

@Matthias Küspert: Are you sure this is not possible from the browser? 

I don't know for the Properties API, but for Rest calls such as updating issues this is entirely possible with https://developer.atlassian.com/cloud/jira/platform/jsapi/request/

Example:

 


declare var AP;

export class JiraIssueFronendAPI {

public static async editIssue(issueKey: string, notifyUsers: boolean, updateDetails: IssueUpdateDetails): Promise<string> {

  return new Promise<string>(async function(ok, nok) {

    let url = `/rest/api/3/issue/${issueKey}?notifyUsers=${notifyUsers}`;

      let options = {
    type: "PUT",
    contentType: "application/json",
    data: JSON.stringify(updateDetails),
    success: function(responseText: string){
    ok(responseText);
    },
    error: function(xhr, statusText, errorThrown) {
    nok(xhr + " " + statusText + " " + errorThrown);
    }
    };

    AP.request(url, options);

    });//promise
  }//function

}
0 votes
Shahryar March 18, 2021

I have the same problem , does anybody know how to fix this problem ?

0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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.

Tharanga July 25, 2017

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. 

Tiago Machado
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 18, 2017

@Tharanga,

Were you able to fix this issue ?

I'm having the exact same issue.

Thanks.

Matthias Küspert October 29, 2017

Any news on this?

I encountered the same problem. However, I authenticated with

AtlassianHostRestClients.authenticatedAsAddon()

from my plugin.

Thanks.

Matthias Küspert October 29, 2017

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

Matthias Küspert November 3, 2017

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."

}

Deleted user February 3, 2018

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

Matthias Küspert February 4, 2018

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