in reply to Accessing attachments using RT::Client::REST
G'day wardmw,
[Disclaimer: I've never used RT::Client::REST and, as I don't have that module installed, I'm unable to provide any local testing for you. What I aim to provide below is some help in troubleshooting your problem.]
I looked at the source code of (the latest versions of) RT::Client::REST and RT::Client::REST::Forms on CPAN. The line numbers you report don't quite marry up with what I'm seeing, so you're probably using an older version. The paths to your locally installed versions are provided: you should view these while reading the remainder of what I have here. Everything I talk about below refers to the current CPAN versions. You should check that assumptions I'm making about slight changes in line numbers are, in fact, valid for your installed versions.
Here's the code in &RT::Client::REST::Forms::form_parse (up to, and including, line 36):
sub form_parse { my $state = 0; my @forms = (); my @lines = split /\n/, $_[0];
So, the first argument to form_parse() would be the reported uninitialized value.
Here's the code in &RT::Client::REST::get_attachment (up to, and including, line 175):
sub get_attachment { my $self = shift; $self->_assert_even(@_); my %opts = @_; my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); my $parent_id = $self->_valid_numeric_object_id(delete($opts{paren +t_id})); my $id = $self->_valid_numeric_object_id(delete($opts{id})); my $res = $self->_submit("$type/$parent_id/attachments/$id"); my $content; if ($opts{undecoded}) { $content = $res->content; } else { $content = $res->decoded_content; } my $form = form_parse($content); my ($c, $o, $k, $e) = @{$$form[0]};
So, $$form[0] would be the undefined value (i.e. not an ARRAY reference).
Furthermore, the $content, passed to form_parse() is, as previously identified, an uninitialized value.
It looks like the value of $content is the problem: generating a warning in form_parse() and, subsequently, an error in get_attachment().
In the code you've posted, you have
get_attachment (parent_id => $id, id => $_)
whereas, the documentation for RT::Client::REST has
get_attachment (parent_id => $parent_id, id => $id, undecoded => $bool +)
For every element in @attachment_ids, you're assigning the return value of $res->decoded_content to $content which, from your description, works successfully a few times and then fails catastrophically.
I would concentrate further efforts in this foreach loop. Perhaps you want to skip further processing of some elements (e.g. with an early next) or maybe include undecoded => $bool in the get_attachment() call (setting $bool to either TRUE or FALSE depending on the element being processed).
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Accessing attachments using RT::Client::REST
by wardmw (Acolyte) on Dec 03, 2015 at 14:35 UTC |