]> git.proxmox.com Git - pve-apiclient.git/blame - examples/example1.pl
add simple example code, bump version to 1.0-2
[pve-apiclient.git] / examples / example1.pl
CommitLineData
d12f292e
DM
1#!/usr/bin/perl -w
2
3# NOTE: you need to run this on a PVE host, or modify the source to
4# provide username/password/hostname from somewhere else.
5
6use strict;
7use PVE::APIClient::LWP;
8
9use PVE::AccessControl;
10use PVE::INotify;
11use JSON;
12
13# normally you use username/password,
14# but we can simply create a ticket and CRSF token if we are root
15# running on a pve host
16
17my $hostname = PVE::INotify::read_file("hostname");
18
19my $ticket = PVE::AccessControl::assemble_ticket('root@pam');
20my $csrftoken = PVE::AccessControl::assemble_csrf_prevention_token('root@pam');
21
22my $conn = PVE::APIClient::LWP->new(
23 #username => 'root@pam',
24 #password => 'yourpassword',
25 ticket => $ticket,
26 csrftoken => $csrftoken,
27 host => $hostname,
28 # allow manual fingerprint verification
29 manual_verification => 1,
30 );
31
32my $res = $conn->get("api2/json/", {});
33
34print to_json($res, { pretty => 1, canonical => 1});