Looking at the documentation for curl, it says:

-d/--data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in
the same way that a browser does when a user has filled in an HTML form and
presses
the submit button. This will cause curl to pass the data to the server
using the content-type application/x-www-form-urlencoded. Compare to
-F/--form.

-d/--data is the same as --data-ascii. To post data purely binary, you
should instead use the --data-binary option. To URL-encode the value of a
form field
you may use --data-urlencode.

If any of these options is used more than once on the same command line,
the data pieces specified will be merged together with a separating
&-symbol. Thus,
using ’-d name=daniel -d skill=lousy’ would generate a post chunk that
looks like ’name=daniel&skill=lousy’.

If you start the data with the letter @, the rest should be a file name to
read the data from, or - if you want curl to read the data from stdin. The
con-
tents of the file must already be URL-encoded. Multiple files can also be
specified. Posting data from a file named ’foobar’ would thus be done with
--data
@foobar.

This means that the content-type header must be
application/x-www-form-urlencoded and the parameters token, sync_token, and
resource_types must be should be in the request body.

The documentation for LWP::UserAgent says:

$ua->post( $url, \%form )

This method will use the POST() function from HTTP::Request::Common to
build the request. See HTTP::Request::Common
<http://search.cpan.org/perldoc?HTTP%3A%3ARequest%3A%3ACommon> for a
details on how to pass form content and other advanced features.

POST $url, $form_ref, Header => Value,...

The $form_ref argument can be used to pass key/value pairs for the form
content. By default we will initialize a request using the
application/x-www-form-urlencodedcontent type.

So, the following should be identical to what the curl command does:

#!/usr/bin/perl

use strict;
use LWP::UserAgent;
use warnings;

my $ua = LWP::UserAgent->new;

$ua->post("https://todoist.com/API/v7/sync";, {
    token => "yourtokengoeshere",
    sync_token => "*",
    resource_types => '["projects"]',
});

die $ua->status_line unless $ua->is_success;

print $ua->decoded_content;


On Wed, Oct 12, 2016 at 12:03 PM <derr...@thecopes.me> wrote:

>
>
>
>
> I would like to get some info from my todoist account with a perl script.
>
> The website provides an example using python and bash.
>
>     curl https://todoist.com/API/v7/sync     -d token=yourtokengoeshere
>    -d sync_token='*'     -d resource_types='["projects"]'
>
>
>
> The curl command works but I would like to use perl and make a todo list
> script that will sync with todoist. There is a cpan module but it doesn't
> work.
>
>
>
> How would I use perl to get the info? I have this
>
>
>
>     #!/usr/bin/perl
>
>     use strict;
>
>     use warnings;
>
>     use LWP::UserAgent;
>
>
>
>     my $url = 'https://todoist.com/API/v7/sync';
>
>     my $token  = 'mytoken';
>
>     my $ua = new LWP::UserAgent();
>
>     my $response = $ua->post($url, token => $token);
>
>
>
> I have no idea how to pass my token or resource types to the api.
>
> Thank you for any help
>
>
>
> --
>
> Derrick Cope
>
>
>
> --from my mutt
>
>
>
> --
>
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>
> For additional commands, e-mail: beginners-h...@perl.org
>
> http://learn.perl.org/
>
>
>
>
>
>

Reply via email to