in reply to post JSON using HTTP::Tiny - cannot parse URL

Are you sure about the arguments of post?
$agent->post( { url => $url, content => $data, headers => $headers } ) +;

The tests show something different.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: post JSON using HTTP::Tiny - cannot parse URL
by GertMT (Hermit) on Apr 23, 2020 at 16:32 UTC
    Thank you for the reference and I promise to look at the tests more often. Very helpful.

    I didn't get it to work yet and will post later when I've solved it.

      alright with the following code I got it to work.
      Thanks!
      sub create_external_inv { my $agent = HTTP::Tiny->new; my $headers = { Accept => "application/json", 'Content-Type' => "application/json", Authorization => "Bearer 123" }; my $url = "https://moneybird.com/api/v2/123/external_sales_invoices"; my $data = { external_sales_invoice => { "reference" => "M-8426", "date" => "2020-03-14", "contact_id" => 456, "details_attributes" => [ { "description" => "coffee", "price" => 2.25, "tax_rate_id" => 891, } ] } }; my $res = $agent->post( $url => { content => to_json($data), headers => $headers } ); print Dumper $res; if ( $res->{success} ) { print "Okay!\n"; } else { print "\n\nNope...\n\n"; } }
      The results print okay!.