frank1 has asked for the wisdom of the Perl Monks concerning the following question:
Am trying to use twilio curl api
but am getting this error:
Error code: 400 Error Message: {"code": 21604, "message": "A 'To' phone number is required.", "more_info": "https://www.twilio.com/docs/errors/21604", "status": 400}here is the code
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; print "Content-type: text/html\n\n"; my $ua = LWP::UserAgent->new; my $sid = "sid"; my $auth = "auth_token"; my $url = URI->new("https://api.twilio.com/2010-04-01/Accounts/$sid/Me +ssages.json"); $url->userinfo("$sid:$auth"); $url->query_form( 'To' => 'whatsapp:+2123456789', 'From' => 'whatsapp:+14155238886', 'Body' => 'hey test msg', ); print $url, "\n"; my $req = HTTP::Request->new(POST => $url); $req->header('Content-Type' => 'application/x-www-form-urlencoded'); my $resp = $ua->request($req); if ($resp->is_success) { print $resp->decoded_content; } else { print $resp->decoded_content; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing curl api
by Corion (Patriarch) on Mar 23, 2022 at 15:12 UTC | |
by frank1 (Monk) on Mar 23, 2022 at 16:05 UTC | |
by Corion (Patriarch) on Mar 23, 2022 at 16:55 UTC | |
by frank1 (Monk) on Mar 24, 2022 at 13:01 UTC | |
by Corion (Patriarch) on Mar 24, 2022 at 13:48 UTC | |
|