How To Create a Session For REST API
Content
Objective
The objective of this article is to show how to use basic authentication to create a session token. Then we
can use the session token for our REST API commands.
Environment
Platform REST API
VSP G/F350 G/F370 G/F700 G/F900
o VSP G350, G370, G700, G900
o VSP F350, F370, F700, F900
o HM850
Virtual Storage Platform (VSP) E Series
o VSP E590
o VSP E790
o VSP E990
o HM900
No SVP
Basic Authentication
Session Authentication
Procedure
CURL
1. Get Base64 encoding for your authorization header (See this KB: How to Login with Basic Authentication
Using REST API )
o you can also use the curl switch -u username:password instead of using -H "Authorization:
Basic bWFpbnRlbmFuY2U6cmFpZC1tYWludGVuYW5jZQ==" . This allows curl to generate the
Base64 header for you.
2. Send the following command to get the session token:
o curl -v -H "Content-Length:0" -H "Accept:application/json" -H "Content-
Type:application/json" -H "Authorization: Basic
bWFpbnRlbmFuY2U6cmFpZC1tYWludGVuYW5jZQ==" -X POST
https://10.4.47.55/ConfigurationManager/v1/objects/sessions --insecure
3. Once you have the "token" or session id you can modify it to send the header as "Authorization:Session
0aac919e-f45d-45cc-b4e7-dce5e64ffd23". For example, see the command below:
o curl -v -H "Accept:application/json" -H "Content-Type:application/json" -
H "Authorization:Session 0aac919e-f45d-45cc-b4e7-dce5e64ffd23" -X GET
https://10.4.47.55/ConfigurationManager/v1/objects/storages/instance --insecure
PowerShell
1. Get Base64 encoding for your authorization header (See this KB: How to Login with Basic Authentication
Using REST API )
2. If you are using HTTPS and need to ignore certificate errors run the commands below:
o in powershell 6 and higher you can add -SkipCertificateCheck to your invoke-resetMethod
command
o in powershell 5 you must run the following code:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object
TrustAllCertsPolicy
3. Setup a header variable for Basic Authentication.
o $headers_basic_auth = @{"Authorization"="Basic
bWFpbnRlbmFuY2U6cmFpZC1tYWludGVuYW5jZQ=="; "Content-Length"="0";
"Accept"="*/*"; "Content-Type"="application/json"}
4. Send the following command to get a session token:
o Invoke-RestMethod -Method "Post" -Headers $headers_basic_auth -Uri
https://10.4.47.55/ConfigurationManager/v1/objects/sessions
5. Setup a header variable for Session Authentication using the token from above.
o $headers_session_auth = @{"Authorization"="Session
d75d874d46ca4f1f8341feaf2c9994a8"; "Content-Length"="0"; "Accept"="*/*";
"Content-Type"="application/json"}
6. Now you can use the $headers_session_auth in the Invoke-ResetMethod commands
o Invoke-RestMethod -Method "Get" -Headers $headers_session_auth -Uri
https://10.4.47.55/ConfigurationManager/v1/objects/storages/instance
CXone Metadata
PageID: 139058
Keywords
https://knowledge.hitachivantara.com/Knowledge/Storage/VSP_G130_GF350_GF370_GF700_GF900/How_To_Crea
te_a_Session_For_REST_API
Solution ID
240403060139058
Last Modified Date
09/16/2024 11:11:11 PM
Attributes
Page Privacy and Permission Assignment
Page Privacy: Private
Page Level Permissions: Employee; Service Partner; Customer; Knowledge Author; Knowledge Editor; IT;
eServices; Knowledge Draft
Article: howto
Pagetype: knowledgearticle
Taxonomy
Storage > VSP G130 G/F350 G/F370 G/F700 G/F900
Collections
Customer
Go to Original Solution
Upland RightAnswers Portal - Version 2024R2