cancel
Showing results for 
Search instead for 
Did you mean: 

Perl REST client

 
shynee
Frequent Visitor

Perl REST client

Does anyone test perl REST client ? I can run curl successfully, but fails through REST client. Tried user id and passwd, also encrypyted authorization Here is my sample code.

#!/usr/local/bin/perl -l

use JSON;
use REST::Client;
use MIME::Base64;

### Skip SSL certificate verification
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

# Set the request parameters
my $host = 'http://<3par storage>:8008';
my $user = '3parid';
my $pwd = 'passwd';

my $client = REST::Client->new(host => $host);
my $encoded_auth = encode_base64("$user:$pwd", '');

# Get Volumes
$client->GET('/api/v1/volumes',
{'Authorization' => "Basic $encoded_auth",
# {'Authorization' => "Basic n3bHCMfkbtPvs0DmBtfnEa==",
'Accept' => 'application/json'});

print 'Response: ' . $client->responseContent() . "\n";
print 'Response status: ' . $client->responseCode() . "\n";
foreach ( $client->responseHeaders() ) {
print 'Header: ' . $_ . '=' . $client->responseHeader($_) . "\n";
}

Always get "invalid session key". same code works perfectly on Netapp's and EMC

Error message

Response: {"code":6,"desc":"invalid session key"}

Response status: 403

Header: Connection=close

Header: Date=Mon, 01 May 2017 15:55:27 GMT

Header: Server=hp3par-wsapi

Header: Content-Type=application/json

Header: Client-Date=Mon, 01 May 2017 15:55:27 GMT

Header: Client-Peer=<3par ip>:8008

Header: Client-Response-Num=1

Following curl syntax works fine.

curl -k -H "Accept:application/json" -H "Content-Type:application/json" --data-binary '{"user":"3parid","password":"passwd"}' 'https://<3par ip>:8080/api/v1/credentials'

{"key":"0-7c2e5ee3yecccd8x430ec1zd56d5308c-d25c0759"}

curl -k -H "X-HP3PAR-WSAPI759: 0-7c2e5ee3yecccd8x430ec1zd56d5308c-d25c0759" 'https://<3par IP>:8080/api/v1/cpgs'

Was wondering I have to pass the session key instead of username/passwd through REST client. But do not know how.

Appreciated

1 REPLY
Dennis Handly
Acclaimed Contributor

Re: Perl REST client

I assume WSAPI is enabled?

showwsapi