Jira cloud API access from app's iFrame

Hi all,

I’m trying to access Jira cloud API from GUI (browser JS) to perform some tasks needed in an app. When looking at the V3 rest API documentation, I see that authentication is done thru header containing mail address and token, as stated here:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-user-properties-propertyKey-put

Question:

  • How to get the mail address of the user currently logged in Jira? I saw the /rest/api/3/myself call, but it seems it does not reply with mail address (only name attribute)

  • How to make the request to the Jira instance? I get logs saying that AP.request is deprecated, although documented here:https://developer.atlassian.com/cloud/jira/platform/jsapi/request/

Thanks a lot!

Fred

Hi,

Find out this documentation about AP.require, but I fail still to be able to POST data on some API entry points, such as this one, receiving 403 error:

      AP.request({
        url: "/rest/api/3/user/properties/" + propertyName + '?accountId=' + deeperData.atlassianAccountId,
        type: 'PUT',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
          },
        body: '{}',
        success: function(responseText){
          console.log(responseText);
        },
        error: function(xhr, statusText, errorThrown){
          console.log(statusText);
        }
      });

I was thiking that my app description may be missing the “WRITE” scope, but that’s not the case, here is the descriptor I’m using:

{
  "development":
  {
    "localBaseUrl": "https://dbfb4e47.ngrok.io",
    "scopes":["READ", "WRITE", "DELETE", "ACT_AS_USER"]
  },
  "production":
  {
    "port": "$PORT",
    "errorTemplate": true,
    "store":
    {
      "type": "postgres",
      "url": "$DATABASE_URL"
    },
    "whitelist":
    [
      "*.jira-dev.com",
      "*.atlassian.net",
      "*.atlassian.com",
      "*.jira.com"
    ],
    "scopes":["READ", "WRITE", "DELETE", "ACT_AS_USER"]
  }
}

I get 403 each time I try to post. I’ve been checking the accountId which is passed as URL request argument, it’s correct. I get 403 error on any Jira cloud instance (my development instance, some other production instances accessing my app)…

Any idea would be much appreciated, as I’m really stucked on that !!!

Thank you,

F.

Hey,

I also had problems with a PUT request for properties and this is what worked in the end. Hopefully, you’ll be able to do something with it.

                await AP.request({
                    url: `/rest/atlassian-connect/1/addons/xxx/properties/${prevState.key}`,
                    type: 'PUT',
                    data: newStateToSave,
                    dataType: 'json',
                    contentType: 'application/json'
                })
                .then( 
//something on success
                )
                .catch(e => console.log(e));

newStateToSave is JSON.stringifyed object.

EDIT:
I’ve noticed now that your scope might not be properly defined. I’m using ACE to create projects and the part with defining environments (what you have in your second post) is defined in config.json whereas scopes are defined inside the atlassian-connect.json. That might also be the cause of it. Check here for more info on app descriptor.

Hope it helps. Cheers

Hi @ChupaCabra,

You were right: scope was not correct, was missing the WRITE value (the descriptor used for the test was not the one I thought). After adding the WRITE value to the app’ scope, it was OK.

But before everything was OK, I got several 400 error code when trying to PUT a property’s value for a user: I then realized that in your example, you set the dataType to json, which is something I was missing too, hence the 400 error code.

Actually, when I look at JIRA Cloud API documentation for setting user property, I don’t see that this has to be set… Documentation seems to be for app to hosted product calls, but not for app iFrame calls (thru AP.request)…

Anyway, thanks a lot for your help, you unblocked me !

Cheers, Fred