Not able to assign a ticket using REST API via R code

I am not able to assign a ticket using REST API to a user as I used to with the following R code. When I checked the documentation, the example shows id (24 characters long generated by JIRA/Atlassian) is required. I am not sure whether the users would share the secret id to use it in the code. Please enlighten me on how to overcome this issue.

library(httr)
library(RJSONIO)
x <- list(fields = list(project = c(key = "ABC"),
                        summary = "SummaryInfo",
                        description = "Description Text",
                        issuetype = c(name = "Story"),
                        assignee = c(name = "jdoe")
            ))
response <- POST("https://xyz.atlassian.net/rest/api/2/issue/",body = toJSON(x),
                 authenticate("janedoe@xyz.com","pxxxxxxxxxxxxxxxxxxxxxxx", "basic"), 
				 add_headers("Content-Type" = "application/json"), verbose())

Hi @RajkumarBalakrishnan!

What error or HTTP status code do you receive back from Jira when this request fails? This may provide clues on what exactly is going wrong.

If this code you are writing is a shell or integration script, and the script needs to log in to Jira as a particular user (eg. yourself), you may like to consider using API Tokens (see https://confluence.atlassian.com/cloud/api-tokens-938839638.html) to authenticate the script. This is generally the simplest form of authentication to use. If you intend to distribute this script to other users, or if you want to use a more secure form of authentication, you may want to consider using OAuth 2.0 (https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/).

When updating an existing Jira issue, I think it is generally a good practice to retrieve the issue from the REST API, and then edit the fields you want to modify on the response object, and then use that amended issue object to POST the update. This is less likely to cause mistakes than manually crafting a Jira issue object to POST back to Jira.

Hope this helps!
Joe.

The issue as detailed above was assigning/updating an Assignee for a ticket programatically. Earlier this way of assigning a user

{ “name”: “gabriele.calligaro” }

was working but now it has changed to this

{ “accountId”: “5b109f2e9729b51b54dc274d” }

When I referred to the documentation it mentions the following which is failing.

{ “id”: “5b109f2e9729b51b54dc274d” }

Apparently the tern needs to be accountId and not id as mentioned in the documentation.

1 Like

I’m glad you were able to solve the problem! I have flagged the incorrect documentation issue with the writing team so that it can be corrected.