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


In reply to Re: Accessing attachments using RT::Client::REST by kcott
in thread Accessing attachments using RT::Client::REST by wardmw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.