Field reporter is unknown, only when using httpClient

1,911 views
Skip to first unread message

Kenny Silanskas

unread,
Mar 14, 2014, 1:35:06 PM3/14/14
to atlassian-...@googlegroups.com
I continue to get back errors from the REST API using httpClient. Two, in fact.

The first is I get "httpRequest userId is deprecated: please use the userKey attribute" whenever I make a PUT request using the client. (More of a warning really, but I'm not sure why)

The second is a straight error while trying to simply update a JIRA issue's single field in a PUT. Code below:

                        var httpClient = addon.httpClient(req);
                        httpClient.put({
                            "url": '/rest/api/2/issue/' + body.issue.key,
                            "headers": {
                                'Content-Type': 'application/json',
                                'Accept' : 'application/json'
                            },
                            body : JSON.stringify({fields:{reporter: {name:"kenny-test\u0040example.com"}}})
                        }, function (err, message, res){
                            console.log(res);
                        });


The error is "errors":{"reporter":"Field 'reporter' cannot be set. It is not on the appropriate screen, or unknown."}}

Note that reporter is indeed a field on the issue and can be set using a REST call through, say, Postman in Chrome. (See below)




Kenny Silanskas

unread,
Mar 14, 2014, 2:43:33 PM3/14/14
to atlassian-...@googlegroups.com
I then tried to load this from a straight json file and it's a different problem but similar. It appears as though somehow its escaping my reporter field oddly:

                        if(devMode) {
                            file =  __dirname + '/data/development.json'
                        } else {
                            file =  __dirname + '/data/production.json'
                        }
                        fs.readFile(file, 'utf8', function (err, data) {
                           if(err) {
                               console.log('Error:' + err);
                               return;
                           } else {
                            var issueBody = JSON.parse(data);
                            var httpClient = addon.httpClient(req);
                            httpClient.put({
                                "url": '/rest/api/2/issue/' + body.issue.key,
                                "headers": {
                                    "Content-Type": "application/json"
                                },
                                encoding : "utf-8",
                                "body" : JSON.stringify(issueBody)
                            }, function (err, message, res){
                                if(err) {
                                    console.log(err);
                                } else {
                                    if(message) {
                                        console.log(message);
                                    }
                                }
                            });
                           }
                        });

Kenny Silanskas

unread,
Mar 14, 2014, 2:44:16 PM3/14/14
to atlassian-...@googlegroups.com
Sorry the new error to go with my last code is similar but different: 

  body: '{"errorMessages":[],"errors":{"reporter":"Field \'reporter\' cannot be set. It is not on the appropriate screen, or unknown."}}' }

Peter Brownlow

unread,
Mar 16, 2014, 9:05:33 PM3/16/14
to atlassian-...@googlegroups.com
Hi Kenny,

I've recently been getting these "not on the appropriate screen, or unknown" JIRA errors myself, and I found them to really mean "you aren't allowed to set that field on that issue using that method". Even though the error message text refers to the UI you get it without going through the UI. :-/

For me, these errors were caused by one of two things:
  • I was trying to set a field that didn't make sense. E.g. when creating an issue there are some fields that it doesn't make sense to set, such as (from memory) how long you've spent working on it.
  • I was missing a permission. E.g. to assign issues requires a JIRA permission which my user didn't have, so I couldn't set the 'assignee' field.

-Peter

Kenny Silanskas

unread,
Mar 17, 2014, 11:58:01 AM3/17/14
to atlassian-...@googlegroups.com
I'm starting to wonder actually if this is related to the fact I haven't done an install hook so I'm not carrying the proper authentication back to the host. Thanks for the tip!

Peter Brownlow

unread,
Mar 17, 2014, 8:43:07 PM3/17/14
to atlassian-...@googlegroups.com
Hi Kenny,

If you're using ACE then you should see the body of the "installed" callback in your console. E.g. if you're running locally in dev mode then every time you run "node app.js" you should see log messages about installing in your local dev instance of the host product, the host getting the descriptor and then the host sending the "installed" callback.

E.g. here's one I ran earlier:

$ node app.js
Watching atlassian-connect.json for changes
Initialized memory storage adapter
Add-on server running at http://localhost:3000
Registering add-on...
Registered with host Confluence:8179004655 at http://localhost:1990/confluence
GET /atlassian-connect.json 200 13ms - 1.22kb
Saved tenant details for Confluence:8179004655 to database
{ key: 'my-add-on',
  clientKey: 'Confluence:8179004655',
  publicKey: '<Confluence public key goes here>',
  sharedSecret: '<your shared secret goes here>',
  serverVersion: '4918',
  pluginsVersion: '1.0.0.rc6-SNAPSHOT',
  productType: 'confluence',
  description: 'host.consumer.default.description',
  eventType: 'installed' }


If you're not seeing this then it may be worthwhile making a fresh add-on with "atlas-connect new <project name goes here>", running it to verify that it's receiving and saving the "installed" callback and then adding to it.

-Peter

Kenny Silanskas

unread,
Mar 25, 2014, 8:56:20 AM3/25/14
to atlassian-...@googlegroups.com
Apologies for bumping an older thread but this is continuing and I think I've now attempted every variation of ways to call this REST service. Let's start with the very simple code which I'm hardcoding to test:

                        var httpClient = addon.httpClient(req);
                        httpClient.put({
                            url:'/rest/api/2/issue/TEST-1',
                            strictSSL: false,
                            json: {"fields": {"reporter": {name: "kenny"}}}
                        }, function(err, message, res) {
                            console.log(message);
                        });

This is in a request context so I know I'm getting my client key, user key, etc. I have verified that in the installed hook you mention above. 

I also browsed to http://localhost:2990/jira/rest/api/2/issue/TEST-1/editmeta and see clearly this...


So we know it can be set. However, I continue (no matter how hard I try to format the JSON in X ways to get this back:

  body:
   { errorMessages: [],
     errors: { reporter: 'Field \'reporter\' cannot be set. It is not on the appropriate screen, or unknown.' } } }

Am I missing some kind of authentication step here? It is my understanding that JWT just "works" once you have registered for the host. For sh**s and giggles, I even added addon.authenticate() as middleware to both the HTTPClient call and the on(wehbook:event) call that fires this PUT. No change so I removed them again. This has to be something and I'm just totally burnt from troubleshooting it.

I'll try anything at this point. :)

Kenny Silanskas

unread,
Mar 25, 2014, 10:09:29 AM3/25/14
to atlassian-...@googlegroups.com
P.S. It might be worth mentioning that to ensure this all would fire correctly, I am simply basing this module off of the webhook-inspector example connect addon. All I did was remove the webhooks I don't need. Full code from webhooks.js:

module.exports = function (app, addon, devMode) {
    /**
     * We are waiting for the JIRA issue updated event
     * so that we can change the reporter from the target
     * to the defined user in [production|development].json
     */
    addon.on('jira:issue_updated', function(evt, body, req){
        var reporterTarget = 'ad...@example.com';
        if(body.issue.fields.reporter.emailAddress == reporterTarget) {
            if(typeof body.changelog.items != 'undefined') {
                for (var index in body.changelog.items) {
                    if(body.changelog.items[index].field == 'assignee'){
                        console.log(req);
                        var httpClient = addon.httpClient(req);
                        httpClient.put({
                            url:'/rest/api/2/issue/TEST-1',
                            strictSSL: false,
                            json: {"fields": {reporter: {name: "kenny"}}}
                        }, function(err, message, res) {
                            console.log(message);
                        });
                    }
                }
            }
        }
    });
};

Kenny Silanskas

unread,
Mar 27, 2014, 10:52:47 AM3/27/14
to atlassian-...@googlegroups.com
To add to the complete absurdity of all of this, I have now tried even doing the SAME operation through the Jira REST API browser logged in as the same user I'm trying to make the change as. Works fine.

So now we know this...
  • Field shows up on createmeta
  • Field can be edited by the "admin" user in the UI
  • Field can be edited by Postman
  • Field can be edited by curl
  • Field can be edited by Atlassian's REST API browser.
But the reporter field (nor any field for that matter - I even tried assignee and summary) cannot be edited using httpRequest.put() . It always comes back as:

  body:
   { errorMessages: [],
     errors: { reporter: 'Field \'anyfieldatall\' cannot be set. It is not on the appropriate screen, or unknown.' } } }

I am using the "admin" as my userKey and still nothing works. What am I doing wrong here or is this just impossible to make calls to the REST API using httpRequest? I know my JWT authentication works because, quite honestly, I can GET the resource back just fine using HTTP request. Just can't PUT (update) a darn thing.

Seb Ruiz

unread,
Mar 28, 2014, 12:21:45 AM3/28/14
to atlassian-...@googlegroups.com
Kenny,

Setting the admin user key is not the correct approach, please read our security docs at https://developer.atlassian.com/static/connect/docs/concepts/security.html

I suspect that the root cause is that the user which is created for your add-on does not have the appropriate permissions to call this resource, and JIRA is returning an obscure and unhelpful error message. Can you please ensure that your add-on user (it will be called addon_your-addon-key) has the expected permission?

Thanks


--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Seb Ruiz
Atlassian

Kenny Silanskas

unread,
Mar 31, 2014, 11:52:28 AM3/31/14
to atlassian-...@googlegroups.com
Seb,

I'm speechless. You're a genius sir. That's exactly what it was. Once I used "req" and gave the addon user the permissions to modify the issues, voila. Thank you a thousand times for helping me finally figure out how this auth stuff worked. On to contribute my help if possible to others. :)
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connect-dev+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Seb Ruiz
Atlassian
Reply all
Reply to author
Forward
0 new messages