Before you can use the REST interface to perform any activities on an appliance you need to authenticate.To authenticate, you submit user name and password in the logon request that you send to the REST interface.
There are two ways to submit them:
- Using query parameters
- Using an authentication header
After a successful authentication, the response contains the session ID, which you must include in each of your following requests.
Using query parameters for authentication
You can submit your credentials with query parameters that you add to the URL in your logon request.
curl -i -X POST "$REST/login?userName=myusername&pass=mypassword"
Using an authentication header
You can also use the Basis Access Authentication method to authenticate, which requires that you submit your credentials in an authentication header.
curl -i -H "Authorization: Basic YWRtaW46d2ViZ2F0ZXdheQ==" -X POST "$REST/login"
In the authentication header, the string after Authorization: Basic is the Base64-encoded representation of your user name and password.
The session ID is sent to you in the response to your logon request. A session ID looks, for example, like this:
It is either contained in the response body:
or in a Set-Cookie header:
In the requests of the sessions that follow the logon request, you must include the session ID as JSESSIONID.
For easier code writing and reading, you can set a variable to the value of the ID and use it for including the ID.
You can append the ID as a matrix parameter to the URL, preceded by a semicolon.
curl -i "$REST/appliances;jsessionid=$SESSIONID"
Alternatively, you can send the ID in a Cookie header.
curl -i -H "Cookie: JSESSIONID=$SESSIONID" "$REST/appliances"
The -c option in curl allows you to collect all cookies in a text file, which is then sent with subsequent requests.
curl -i -c cookies.txt -H "Authorization: Basic YWRtaW46d2ViZ2F0ZXdheQ==" -X POST "$REST/login"
For sending a cookie file with a request, the -b option is used:
curl -i -b cookies.txt "$REST/appliances"