Getting 403 - Permission Denied through Jira REST API POST request

I have a script that copies an issues from our cloud environment and re-creates it in our Data Center instance.

The script can duplicate the issue in Data Center fine, but when copying comments it fails with this error:

Exception in thread “main” RestClientException{statusCode=Optional.of(403), errorCollections=}

Can any one help decipher what could be causing this?

Here is the code that it errors on:

    private void addComment(final Issue onPremIssue, final Comment cloudComment) {
        final User cloudAuthor = getCloudUser(cloudComment.getAuthor());
        final Optional<String> onPremAuthor = findOnPremUser(cloudAuthor.getEmailAddress()).map(BasicUser::getSelf).map(URI::toString);
        final String body =
                "Cloud Comment Date: " + cloudComment.getCreationDate() +
                        ", Cloud Comment Author:  [" + cloudAuthor.getEmailAddress() + "|" +
                        onPremAuthor.orElse("mailto:" + cloudAuthor.getEmailAddress()) + "]" +
                        "\n\n" +
        final Comment onPremComment = Comment.valueOf(body);
        onPremJira.getIssueClient().addComment(onPremIssue.getCommentsUri(), onPremComment).claim();

Here is the error:

Exception in thread “main” RestClientException{statusCode=Optional.of(403), errorCollections=}
at com.tool.jira.JiraMigrationTool.addComment(

I would guess it could be a mistake somewhere in your code.

I just added my code to the original post.

Your newly added code sample doesn’t provide any clues as to which version of which REST API endpoint you’re sending the request to or how you’re encoding the string body, other than it being text, before submitting it as JSON. What testing have you done with just a very simple one word comment? What testing of the raw request have you done using an API test tool like Postman to know your request works before committing it to code?

Without any of this you’re essentially just saying… “Here is some faulty Java code. Proof read it for me and do my debugging for me”

Also, what role does the Jira Migration Tool have in this ‘script’ of yours?