Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84683members
354037posts

Anyone have a working example of calling the REST API from Perl ?

EcoStruxure IT forum

A support forum for Data Center Operation, Data Center Expert, and EcoStruxure IT product users to share knowledge on installation, configuration, and general product use.

Solved
DCIM_Support
Picard
Picard
0 Likes
6
964

Anyone have a working example of calling the REST API from Perl ?

This question was originally posted on DCIM Support by david rose on 2018-09-17


(CID:134032557)


Accepted Solutions
DCIM_Support
Picard
Picard
0 Likes
3
965

Re: Anyone have a working example of calling the REST API from Perl ?

This answer was originally posted on DCIM Support by david rose on 2018-09-17


Hi Ed,

 

Happy to look at your CURL code - might help we see what's going on - or give me a base to work from.

Currently I have the simplest of Perl scripts trying to get a simple of assets (small steps).

I'm getting "500" error being returned.

 

500 Can't connect to dco.rhino-hosting.com:443 (Bad file descriptor) at simple.pl line 23.
 

This is against one of the the training servers.

 

use strict;
use warnings;
use LWP::UserAgent ();

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->credentials(
'dco.rhino-hosting.com:443',
'ISXO',
'user' => 'password'
);
$ua->default_header( Accept => 'application/json' );

my $response = $ua->get('https://dco.rhino-hosting.com/api/v8.1/assets');

if ($response->is_success) {
print $response->decoded_content; # or whatever
}
else {
die $response->status_line;
}
 

Thanks,

dave

(CID:134032607)

See Answer In Context

6 Replies 6
DCIM_Support
Picard
Picard
0 Likes
0
965

Re: Anyone have a working example of calling the REST API from Perl ?

This answer was originally posted on DCIM Support by Ed Tarento on 2018-09-17


Hi David

I haven't used any of the REST PERL packages as I've tried to use only the installed software for SE for my scripting.  This is no doubt something that each client/programmer will have a view on.  Therefore I simply use a PERL system call and CURL.  I would not call this production or professional grade solution but it gets the job done.  If that helps, I'm happy to share a script 

Cheers

Ed 

(CID:134032589)

DCIM_Support
Picard
Picard
0 Likes
3
966

Re: Anyone have a working example of calling the REST API from Perl ?

This answer was originally posted on DCIM Support by david rose on 2018-09-17


Hi Ed,

 

Happy to look at your CURL code - might help we see what's going on - or give me a base to work from.

Currently I have the simplest of Perl scripts trying to get a simple of assets (small steps).

I'm getting "500" error being returned.

 

500 Can't connect to dco.rhino-hosting.com:443 (Bad file descriptor) at simple.pl line 23.
 

This is against one of the the training servers.

 

use strict;
use warnings;
use LWP::UserAgent ();

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->credentials(
'dco.rhino-hosting.com:443',
'ISXO',
'user' => 'password'
);
$ua->default_header( Accept => 'application/json' );

my $response = $ua->get('https://dco.rhino-hosting.com/api/v8.1/assets');

if ($response->is_success) {
print $response->decoded_content; # or whatever
}
else {
die $response->status_line;
}
 

Thanks,

dave

(CID:134032607)

DCIM_Support
Picard
Picard
0 Likes
0
965

Re: Anyone have a working example of calling the REST API from Perl ?

This comment was originally posted on DCIM Support by Ed Tarento on 2018-09-17


Try HTTP rather than HTTPS - just as a test

(CID:134032614)

DCIM_Support
Picard
Picard
0 Likes
0
965

Re: Anyone have a working example of calling the REST API from Perl ?

This comment was originally posted on DCIM Support by Christopherus Laurentius on 2018-09-17


+1 on this comment.

Disable the auto routing from http to https via webmin if you are testing via http.

 

(CID:134032633)

DCIM_Support
Picard
Picard
0 Likes
0
965

Re: Anyone have a working example of calling the REST API from Perl ?

This comment was originally posted on DCIM Support by david rose on 2018-09-18


That's done the trick - thanks!

And changed the authorisation to Basic.

 

Code now looks like this (in case anyone else is interested).

 

#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use Data::Dumper;
use JSON;
my $address = "dco.rhino-hosting.com";
my $port = 80;
my $username = "user";
my $pass = "password";
my $url = "http://$address:$port/api/v8.1/assets";
print $url . "\n";
my $browser = LWP::UserAgent->new('Mozilla');
my $req = HTTP::Request->new(GET => $url);
$req->authorization_basic($username, $pass);
my $res = $browser->request($req);
print Dumper($res) . "\n";
my $response = from_json($res->decoded_content);
print Dumper($response) . "\n";

(CID:134032974)

DCIM_Support
Picard
Picard
0 Likes
0
965

🔒 Closed

This question is closed for comments. You're welcome to start a new topic if you have further comments on this issue.