Can you store User Properties with an addon?

The docs for Jira Cloud are a bit contradictory about whether an addon can store properties against a user.
https://developer.atlassian.com/cloud/jira/platform/storing-data-without-a-database/
This page says it’s possible, yet links to the Cloud API reference which says addons don’t have access to the user property endpoints.
The page was last updated in August 2017, and the API reference page doesn’t seem to have a last updated date on it.

I’m even having trouble using /rest/api/2/user/properties outside of the addon. I’ve explicitly added properties to my user and I get an empty array back for the keys.

@rmassaioli

1 Like

Hi @satvik,

When you say you’ve “explicitly added properties to your user” do you mean through the UI? Or through a REST API request outside of your app?

Can you share the specific requests that you are making from your app?

1 Like

I mean through the UI. Are those a second set of user properties?
I couldn’t manage to add any properties to a user via the API.

I’m GET-ing:

  • /rest/api/2/user/properties/${property}?userKey=${userKey}
    *
  • /rest/api/2/user/properties?userKey=${userKey}
    • This succeeds but never gives any keys.

I’m using POST on:

  • /rest/api/2/user/properties/${property}?userKey=${userKey} with the prop value as the body
  • /rest/api/2/userProperties/ with a stringified JSON object with the key, status and value.

I’m getting 403's on both POST's.

Yes the ones that are set in the UI are different. You can GET them with the userProperties API but they are not available to apps and therefore not really useful. As an app, you should be using /rest/api/2/user/properties/.

The properties API accepts PUT, not POST. So to set a user property, your request would be something like PUT to https://example.atlassian.net/rest/api/2/user/properties/test-user-prop?username=admin

And to look up that same property:
GET https://example.atlassian.net/rest/api/2/user/properties/test-user-prop?username=admin

4 Likes

Thank you, the docs aren’t very clear, and it’s totally my fault I missed it was a PUT instead of POST.

I’ve submitted feedback on the docs and once again thank you for taking the time to resolve this.

2 Likes

Hi all,

I’m trying to save user properties from a Jira cloud add-on, but I’m getting a 403 return code. The scenario is that the current logged in user makes a client code to save a property as follows:

setupAjax: function()
  {
    var token = $("meta[name=token]");

    $.ajaxSetup(
    {
      headers: { 
        'Authorization': 'JWT ' + token.attr("content"),
        'Accept': 'application/json',
        'Content-Type': 'application/json' }
    });
  }

AP.require('request', function(request)
      {
        request(
        {
          url: '/rest/api/3/user/properties/' + propertyKey + '?accountId=' + deeperData.atlassianAccountId,
          type: 'PUT',
          body: deeperData.productTourSections,
          success: function(response)
          {
            console.log("saveUserPropertiesPromise():success");
            console.log(response);
          },
          error: function(response)
          {
            console.log("saveUserPropertiesPromise():error");
            console.log(response);
          }
        });
      });

The documentation states that:

Permissions required:

  • Administer Jira global permission, to set a property on any user.
  • Access to Jira, to set a property on the calling user’s record.

Hence my question: for an add-on to save user properties, is there an admin action to perform so that any user using the add-on can save its user properties?

Thank you,

F.

Hi Fredric,

I’m not sure your $.ajaxSetup function actually works in this context because you’re not using $.ajax, you’re using AP.request. You’ll have to pass the headers to request as shown here:
https://developer.atlassian.com/cloud/jira/platform/jsapi/request/

Edit: Actually, you only need that token for requesting back to your Connect server. Hmmm.

Are you sure the accountId you’re using is the user that’s running the addon or are you trying to set another user’s property without being an admin?

Hi @satvik,

Thank you for the tips. You were right, the $.ajaxSetup function was not necessary, and the accountId & token were OK.

Problem was in request’s configuration: auth header was not OK (wrong mail address). With the correct mail address gotten thru:

GET /rest/api/3/myself

Everything is working like a charm now.

Thank you for help,

Fred