#!/usr/bin/env perl # # wctest.pl - A test to retrieve and save an attachment. use strict; use warnings; use RT::Client::REST; use RT::Client::REST::Ticket; use Log::Log4perl; my $user='xxxx'; my $pass='yyyy'; my $rt = RT::Client::REST->new( server => ('https://rt.local'), basic_auth_cb => ( sub { return ($user, $pass); } ), ); $rt->login( username=> $user, password=> $pass,); # # Get attachments using get_attachment # my @results = $rt->search( type => 'ticket', query => "id=51447" ); my ($id, @atch_ids, $atch_id, $atch); for $id (@results) { @atch_ids = $rt->get_attachment_ids( id => $id); for $atch_id (@atch_ids) { $atch = $rt->get_attachment (parent_id => $id, id => $atch_id, undecoded => 1); next if (! defined($atch->{'Filename'}) ); next if ($atch->{'Filename'} eq ''); open(FH, ">", $atch->{'Filename'}) || die "Can't open file: $!"; syswrite(FH, $atch->{'Content'}); close FH; } }