Calling Restful API using linux curl

RESTful knowledge exchange

Calling Restful API using linux curl

Veeam Logoby fermon » Tue Nov 25, 2014 11:22 pm

I'm having some difficulties with the syntax using linux. After generating a new login session with curl --get http://10.88.10.20:9399/api/ Next I issue the curl command Curl -H -D 'Authorization: Basic <Encoded string Here>' http://10.X.X.X:9399/api/sessionMngr/ .

The response I get is:

curl: (6) Could not resolve host: Authorization
<?xml version="1.0" encoding="utf-8"?><Error StatusCode="401" Message="Identity was not authenticated." xmlns="http://www.veeam.com/ent/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
fermon
Novice
 
Posts: 5
Liked: never
Joined: Sat Oct 11, 2014 2:47 am
Full Name: fermon grays

Re: Calling Restful API using linux curl

Veeam Logoby v.Eremin » Wed Nov 26, 2014 8:18 am

Are you positive that the given account has the Portal Administrator, Portal User or Restore Operator role in the Enterprise Manager? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Calling Restful API using linux curl

Veeam Logoby poulpreben » Wed Nov 26, 2014 8:37 am

This works for me:

Code: Select all
$ curl -XPOST -v -u user:pass http://10.0.0.7:9399/api/sessionMngr/?v=v1_1 -H "Content-Length: 0"
$ wget --method POST http://10.0.0.7:9399/api/sessionMngr/?v=v1_1 --http-user=user --http-password=pass --header="Content-Length: 0" -O - -S


Also, you do not create the logon session using the GET request mentioned. These two examples create the session and return the session token requires. Pro tip is that cURL actually supports the Set-Cookie header as well, so check the documentation for this feature to make your life much easier :)
poulpreben
Expert
 
Posts: 935
Liked: 398 times
Joined: Mon Jul 23, 2012 8:16 am
Full Name: Preben Berg

Re: Calling Restful API using linux curl

Veeam Logoby poulpreben » Wed Nov 26, 2014 5:31 pm 1 person likes this post

fermon wrote:Where did you find the uri info < ?v=v1_1 >

(Answering in the public forum instead of private message, since this might be valuable to other forum members too.)

A good way to discover and learn the API is using the built-in web client. The web client is available on http://enterprise-manager:9399/web or https://enterprise-manager:9398/web depending on whether you prefer HTTP or HTTPS.

Using this URL, you should see a screen similar to this:
Image

All the links can be used for navigation, and you will constantly be presented with a list of available resources. After creating the session using an empty POST session to the URL highlighted above, you will see the API overview. Most importantly, please note the <SessionId> tag at the bottom of the response.
poulpreben
Expert
 
Posts: 935
Liked: 398 times
Joined: Mon Jul 23, 2012 8:16 am
Full Name: Preben Berg


Return to RESTful API



Who is online

Users browsing this forum: No registered users and 4 guests