This post is more than 5 years old
4 Posts
0
13007
How can I use curl to interact with the Unity REST API
My issue is around getting authorization information.
"curl -k -X GET https://ipaddressofmyarray/api/types/basicSystemInfo/instances" works fine, because it does not need any authorization
I then tried:
curl -H "Accept:application/json" -H "Content-type:application/json" -H "X-EMC-REST-CLIENT:true" -H "Authorization:Basic XXXXXXXXXXXXXXXX" -k -X GET https://ipaddressofmyarray/api/types/system/instances?fields=name,model,serialNumber
Where XXXXXXXXXXXXXXXX is the Base64 encoding of "admin:myarraypassword"
I know that I need to get the EMC-CSRF-TOKEN/Ticket granting cookie but was expecting to get this with the first GET request I do - should I be using a different URL to do this initial authorization, or does any GET to a valid URL work?
I've seen perl and python examples, but as I am not familiar with either of these 2 languages, then this doesn't help me much.
The response I get is:
Found
The document has moved https://ipaddressofmyarray/cas/login?service=https%3a%2f%2fipaddressofmyarray%2fapi%2ftypes%2fsystem%2finstances%3ffields%3dname,model,serialNumber">here.
Matt
mattdulson
4 Posts
0
May 8th, 2017 01:00
Thanks Greg, provided I tell curl to write a cookie, with the -L option I'm now getting a good response, and if I then tell curl to use this cookie for subsequent commands I don't need to use the "-H "Authorization:Basic XXXXXXXXXXXXXXXX" option so I can get on with my automation - many thanks.
Matt
Anonymous
5 Practitioner
5 Practitioner
•
274.2K Posts
1
May 5th, 2017 10:00
Hi Matt,
Please include the -L option with curl, that follows the 302 redirect, to the login url,
Thanks,
Greg
mattdulson
4 Posts
0
May 8th, 2017 08:00
Just in case this is of use to anyone else, the above is OK for GET commands, but POST/DELETE gets a bit more complicated. In theory it's just a case of grabbing the EMC-CSRF-TOKEN on the first GET after the login, but unless the cookie curl uses is updated as part of this initial GET, with MOD_AUTH_CAS_S then EMC-CSRF-TOKEN changes on every subsequent GET.
Rainer_EMC
8.6K Posts
0
May 8th, 2017 23:00
just curious - if you dont want to do real programming why not use the UEMCLI which gives you the same functionality as the REST API ?
I think its easier to script than REST via curl
mattdulson
4 Posts
0
May 9th, 2017 00:00
It's principally because this is part of some automation for AIX systems, and there is no CLI for AIX, only Linux.
Matt
Rainer_EMC
8.6K Posts
0
May 9th, 2017 08:00
thanks - that makes sense
I would suggest to look at using Perl then - seems to be easier to deal with REST than curl
I think we do have Perl examples somewhere
other option would be to ssh into the SP and use the UEMCLI there
kelleg
4.5K Posts
0
May 10th, 2017 09:00
Please remember to mark your question Answered when you get the correct answer and award points to the person providing the answer. This helps others searching for a similar issue. In the case of this particular question, making the Question Answered will help others looking for similar questions about Curl.
glen
savvyP
1 Message
0
December 30th, 2019 01:00
Please share your c# code
Rainer_EMC
8.6K Posts
0
January 9th, 2020 06:00
This thread - besides being over 2 years old - is about using curl and not C#
TiborSymm96
1 Message
0
August 7th, 2020 14:00
Could you write result command line for curl with -L option and response from Unity ?
CrazyHorseGuy
2 Posts
0
October 11th, 2021 20:00
After another tweak of the user account, and using -L in the curl command, I keep getting a whole bunch of 302's getting returned. Not sure whats happening here???
* Mark bundle as not supporting multiuse
< HTTP/1.1 302 Found
< Date: Tue, 12 Oct 2021 03:40:22 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=63072000; includeSubdomains;
< Set-Cookie: MOD_AUTH_CAS_S=aed4093f7bee0d2ead066509f5caa0ada3046770;Secure;Path=/; HttpOnly
< Location: https:// /api
< Content-Length: 209
< Content-Type: text/html; charset=iso-8859-1
<
* Ignoring the response-body
* Connection #0 to host left intact
* Maximum (50) redirects followed
curl: (47) Maximum (50) redirects followed
CrazyHorseGuy
2 Posts
0
October 11th, 2021 20:00
Hi, I keep getting a 401 Unauthorized returned by Curl after I use "-L" to follow the redirect. Is there a special Role for the user account i'm using that has the minimum required permissions to access the API? I didn't create the user account myself, as this was done by our managed service provider.
DELL-Sam L
Moderator
Moderator
•
7.1K Posts
0
October 12th, 2021 09:00
Hello CrazyHorseGuy,
Here is a link to a kb that maybe of assistance. https://dell.to/3mQgrzt