Dell EMC Unity: How To Use cURL to interact with Unity REST API (User Correctable)
Summary: Users might use cURL tool to manage the Unity storage via its REST API. The cURL command is a quick alternative to Perl or other scripting languages which leverage standard JSON dataSee more
cURL version tested: 7.37.0 OS tested: SUSE Linux (SLES 12) Unity OE tested: 4.1.1.9138882
The article describes the following actions through REST API with cURL commands: 1. Logging into the Unisphere Management REST API server.
2. Querying an existing LUN information.
3. Creating a new LUN.
4. Resizing the newly created LUN.
5. Querying the resized LUN.
6. Deleting that LUN.
7. Logging out of the Unisphere Management REST API server.
Here below are the related commands and outputs: The following information in the commands examples need to be replaced by the ones in your own case.
- Unisphere admin user name: admin
- admin account password: P@ssw0rd
- VNXe management IP: 10.32.106.115
- cookies file name: cookies1.txt
- EMC-CSRF-TOKEN: Session token retrieved from the first logging command verbose output
- Old LUN CLI ID: sv_7
- New LUN name: curlLUN
- New LUN CLI ID: sv_19
1. Logging into the Unisphere Management REST API server. curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -u "admin:P@ssw0rd" -c cookies1.txt -verbose -L -k
https://dell.to/3DzWaHL
EMC-CSRF-TOKEN information in the verbose output ==>
EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=
7. Logging out of the Unisphere Management REST API server. curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=" -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k
https://dell.to/3THn4TP
Result ==>
Logout successful
Additional Information
Explanation about the cURL parameters.
X-EMC-REST-CLIENT: true This tells the server to use the HTTP Basic access authentication mechanism to authenticate the login request.
EMC-CSRF-TOKEN Token header, which is required for POST and DELETE requests.
This token header is good for the entirety of the session.
This token string is retrieved from the verbose output of the first login cURL command.
-u "admin:P@ssw0rd" Passing the username and password to REST API server for authentication in the login request.
-verbose Verbose output of the communication process. Useful to retrieve the EMC-CSRF-TOKEN from the login command output.
Also useful when there is error of the command to have debug level information.
-H "Accept: application/json" To indicate that the format of the response content is JSON.
-H "Content-type: application/json" To indicate that the format of the request contains body is JSON; required if there is a request body.
-c cookies1.txt Set the cookies file name to record cookies information.
-b cookies1.txt Get the cookies information from previously saved cookies file.
-L Necessary when there is URI redirection (HTTP 302). The command will resend the parameters to redirected URI.
-d '{"name":"curlLUN","lunParameters":{"pool":{"id":"pool_2"},"isThinEnabl ed":"false","size":"1073741824"}}' curl data format to fit into JSON data structure
-k Ignore the SSL certificate verification.
This option explicitly allows curl to perform "insecure" SSL connections and transfers.
Any further question, please refer to the attached Unity REST API programmer guide.
Hi Sam, This link require permission, which i don't have. I have gone through one same scenario where solution is marked by adding -L in curl. I did tried but no change.
DELL-Sam L
Community Manager
•
8056 Posts
•
34380 Points
793
0
Posted October 25th, 2022 09:00
Hello samrathal,
Here is a link to a kb that maybe of assistance.
https://dell.to/3VUBjq1