Reindex jira via Rest API

paul grant July 15, 2014

When trying to initiate a jira re-index using rest via:

http://JIRA_INSTANCE/rest/api/2/reindex?type&indexComments&indexChangeHistory

I receive the following:

A task could not be found for the given task id
 
Is this feature fully implemented and has anyone managed to get this working?
 
Thanks,
Paul

3 answers

1 accepted

0 votes
Answer accepted
paul grant August 18, 2014

Below is the perl code used to carry out a reindex (thought this may be helpful):

use strict;

use warnings;

 

use REST::Client;

use MIME::Base64;

use JSON;

 

my $JIRA_HOST = $ENV{JIRA_HOST};

 

&main;

 

sub main {

        my ($content, $subject);

 

        my $username = $ENV{JIRA_ADMIN_USER} || die "JIRA_ADMIN_USER env var not set";

        my $password = $ENV{JIRA_ADMIN_PASS} || die "JIRA_ADMIN_PASS env var not set";

 

        my $headers = {

                'X-Atlassian-Token' => 'nocheck',

                Authorization => 'Basic ' . encode_base64($username . ':' . $password)

        };

        my $client = REST::Client->new();

        $client->setHost($JIRA_HOST);

        my $response = $client->POST('/rest/api/2/reindex', $content, $headers);

 

        if($response->{_res}->{_rc} != 202) {

                $subject = "Error running JIRA reindex on $JIRA_HOST return code $response-{_res}->{_rc} <EOM>";

        } else {

                my $current_progress = 0;

                while($current_progress != 100) {

                        my $response = $client->GET('/rest/api/2/reindex?taskId', $headers)->{_res};

                        my $content = JSON->new->utf8->decode($response->{_content});
$current_progress = $content->{currentProgress};

                        sleep 10;

                }

                $subject = "JIRA weekly reindex has been completed for $JIRA_HOST <EOM>";

        }

 

        send_email();

}

Eric Hartojo May 7, 2020

Hi Paul, 

I'm not familiar about perl but it seems like you have the answer that I'm looking for. I need to reindex jira and send email afterwards.

When I run your code in cmd, it is complaining that it can't locate REST/Client.pm

JIRAREINDEX.png

0 votes
paul grant August 17, 2014

I needed to include empty content in the POST request so instead of this:

$client->POST('/rest/api/2/reindex?type=FOREGROUND', $headers);

I had to include:

$client->POST('/rest/api/2/reindex?type=FOREGROUND', $content, $headers);

Carla Ann Rowland
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 17, 2020

did that solve it? Because I get the same error and I have Active Directory (if that makes a difference) so when I do full reindex get the error message.

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2014

Are you doing a post there ? or a get ? AFAIK, you need to POST it

(edit) ... and be sure to have a user which have admin permission for reindex.

paul grant July 17, 2014

I'm doing this directly in the browser, I do have admin permissions.

Luciano Fagundes
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 17, 2014

Paul

As per our rest documentation you can do both GET and POST. Can you try to use the Google Chrome REST Console addon to do so as well?

Can you also try to run the REST command below?

Hope it helps!

Cheers

Luciano Fagundes

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2014

As per your documentation, GET returns the status (if you have admin perms). POST is needed to start reindex, and this is what Paul tries to do. ;)

Suggest an answer

Log in or Sign up to answer