Skip to end of metadata
Go to start of metadata

This tutorial will write a Perl script which removes a user from all open reviews – this might be useful if a reviewer is no longer available, and is holding up the completed status of all their reviews.

First install the REST::Client and JSON packages from CPAN – the details of doing this will depend on your platform.


Data::Dumper is very useful when developing Perl REST clients:

Our script will retrieve a list of all open reviews, get the uncompleted reviewers for each review, and if one of these matches the user passed as a command line parameter we will complete the reviewer.

  • Get all open reviews: GET /reviews-v1/filter/{filter}, setting {filter} to allOpenReviews.
  • Get the incomplete reviewers for each of these reviews: GET /reviews-v1/{id}/reviewers/uncompleted
  • Remove a reviewer: POST /reviews-v1/{id}/reviewers/{username}

When JSON produces lists of objects, the structures produced depend on the number of items in the list.
If the /reviews-v1/filter URL returns a single review, the JSON will look like this:

but if several reviews are returned the JSON will be:

and if there are no reviews it will simply be:

The toList function in the code below handles the three cases above.

  • No labels


  1. Anonymous

    When I run the example perl script, it give me "malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "<!DOCTYPE HTML PUBLI...") at line 30.

    Appreciated if any help.

    1. Anonymous

      verify the url's you are requesting:

      '/rest-service/reviews-v1/filter/allOpenReviews', vs '/fecru/rest-service/reviews-v1/filter/allOpenReviews',

      1. I am alsoo facing the same error.As you said If url is wrong it should not work in Browser am i correct?But When i give same URL in browser i can able to get json content



  2. Anonymous

    could you please tell me how to attach file to JIRA issue using rest::cient in perl ?

  3. Anonymous

    > could you please tell me how to attach file to JIRA issue using rest::cient in perl ?


    here is what i came up with... 


    # rest_add_jira_attachment ($rest_hash, $key, $filename)
    $rest_hash = {url=> '', user=> 'jira_admin', password=> 'password_for_jira_admin'}

    (c) Max Uzunov
    sub rest_add_jira_attachment {
    my ($rest_hash, $key, $filename) = (@_);

    require Data::Dumper;
    require MIME::Base64;
    require URI;
    require URI::Escape;

    my (undef, undef, $strip_fn) = File::Spec->splitpath ($filename);
    my $rest_api_suffix = '/rest/api/latest';
    my $uri = URI->new( $rest_hash->{url} );
    $uri->path( $uri->path . $rest_api_suffix );

    my $rest = REST::Client->new();
    $rest->setHost( $uri );
    $rest->addHeader(Authorization => 'Basic ' . MIME::Base64::encode_base64($rest_hash->{user} . ':' . $rest_hash->{password}));
     $rest->getUseragent->agent('Adding JIRA attachment using REST::Client');

    my $jira_path = "/issue/$key/attachments";
    my $jira_uri = $uri->path;

    my $request =
    POST ( $uri->path
    ,Content_Type => 'form-data'
    ,'X-Atlassian-Token' => 'nocheck'
    ,Content => [file => [$filename, $strip_fn],]
    print "URI:\t" . $uri->path . "\n";
    print Dumper($request) . "\n";

    my $headers = {'Content-Type' => $request->header('Content-Type')};
    $headers->{'X-Atlassian-Token'} //= 'nocheck';

    my $response =
    print Dumper($response) . "\n";

    return $rest;






      my $filename = 'a.sql';
      my $rest_hash = { '', 'jira_admin', 'jira_password' };
      my $rest = rest_add_jira_attachment ($rest_hash, $RELEASE_TAG, $filename);
      print "=" x 80 . Dumper($rest) . "\n";





  4. i need this code in java... can anyone help me please... 

  5. This code needs:

    use strict;
    use warnings;