jira-node / node-jira-client

A Node.js wrapper for the Jira REST API
https://jira-node.github.io/
MIT License
449 stars 171 forks source link

Unable to addWatchers #311

Closed tylerhammer closed 4 years ago

tylerhammer commented 4 years ago

I'm utilizing the addWatcher method, and I seem to get some weird behavior. When I use the method in my function, it doesn't add the user and seems to return as if I was doing a GET against the URL. I confirmed in a packet capture that I am doing a POST, but I'm not sure what it doesn't like. When I complete this request in POSTMAN I have no issues.

                cloudJira
                  .addWatcher(issueArray[i], accountId)
                  .then((data) => {
                    console.log(data);
                  })
                  .catch((error) => {
                    console.log(error);
                  });

I have a feeling I'm just missing something super simple here but any help would be appreciated.

tylerhammer commented 4 years ago

Just to do some additional validate, if I remove the jira-client and use node-fetch, it works as I would expect.

fetch(
  'https://<DOMAIN>.atlassian.net/rest/api/3/issue/<ISSUE>/watchers',
  {
    method: 'POST',
    headers: {
      Authorization: `Basic ${Buffer.from(
        '<USER>:<API>'
      ).toString('base64')}`,
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    body: `"<ACCOUNTID>"`,
  }
).then((response) => {
  console.log(
    `Response: ${response.status} - ${response.statusText}`
  );
});
tylerhammer commented 4 years ago

As I suspected, this was an issue on my end. I had misspelled "protocol" in my configuration and it was defaulting to http. Correcting my spelling mistake provided me with the response I expected.