Announcement Banner

mattdulson

updated

5 years ago

0

13382

May 3rd, 2017 07:00

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:

302 Found

Found

The document has moved https://ipaddressofmyarray/cas/login?service=https%3a%2f%2fipaddressofmyarray%2fapi%2ftypes%2fsystem%2finstances%3ffields%3dname,model,serialNumber">here.

thanks

Matt

  • 10655

    0

    Posted 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

  • 10655

    0

    Posted 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

    6 Operator

    •

    8645 Posts

    10657

    0

    Posted 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

  • 10660

    0

    Posted 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

    6 Operator

    •

    8645 Posts

    10660

    0

    Posted 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

    6 Operator

    •

    4537 Posts

    10660

    0

    Posted 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

    8373

    0

    Posted December 30th, 2019 01:00

    Please share your c# code

  • Rainer_EMC

    6 Operator

    •

    8645 Posts

    4093

    0

    Posted January 9th, 2020 06:00


    @savvyP wrote:

    Please share your c# code


    This thread - besides being over 2 years old - is about using curl and not C#

  • TiborSymm96

    1 Message

    5260

    0

    Posted August 7th, 2020 14:00

    Could you write result command line for curl with -L option and response from Unity ?

  • 618

    0

    Posted 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