3PAR Users Group

A Storage Administrator Community




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: perl REST client
PostPosted: Mon May 01, 2017 11:18 am 

Joined: Mon May 01, 2017 9:53 am
Posts: 1
Does anyone test perl REST client ? I can run curl successfully, but fails through REST client. Here is my sample code.

Quote:
#!/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 ALL incidents
$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

Quote:
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.

Quote:
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

Yezdi


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group | DVGFX2 by: Matt