REST API knowledge exchange
Post Reply
rwgustason
Novice
Posts: 9
Liked: 3 times
Joined: Aug 13, 2019 1:22 pm
Full Name: Ryan Gustason
Contact:

Beginner Veeam API using curl

Post by rwgustason »

Hello,

I am new to the Veeam API and RestAPI in general.

I'm attempting to connect to my Veeam API using curl. I've tried

Code: Select all

curl -k -u user@domain.tld:<password> GET "https://<server>:9398/api/sessionMngr/?v=latest"
This returns a 502 not resolvable.

I've been looking at examples but so far I am unsure if I even have the user configured right. currently user@domain.tld is set up as a portal administrator. Does anyone know how to call the API using curl from a linux machine to get Session Tokens and login with that session to get info on jobs, etc...

My goal is to dump this data to flat files using a script and then build tables for a dashboard I currently have setup for our storage infrastructure.

Thanks!
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Beginner Veeam API using curl

Post by oleg.feoktistov » 1 person likes this post

Hi Ryan and Welcome to the Community Forums!

There is nothing wrong with your user config. You specified it in UPN format, which is correct for curl. It also has relevant role in EM.
So, the actual cause here is that you are trying to create a session to EM API with GET method :wink:
Just change it to POST and that should do. Though curl might be grumbling on Content-Length property not specified in the header, so set it to 0 and you are good to go:

Code: Select all

curl -X POST -k -v -u user@domain.tld:<password> https://<server>:9398/api/sessionMngr/?v=latest -H "Content-Length: 0"
By the way, -v flag may help with connection debugging.

Hope that helps,
Oleg
rwgustason
Novice
Posts: 9
Liked: 3 times
Joined: Aug 13, 2019 1:22 pm
Full Name: Ryan Gustason
Contact:

Re: Beginner Veeam API using curl

Post by rwgustason »

Thanks for that. How would I then use that session using curl to get a list of backupServers?

I've tried:

Code: Select all

curl -X GET -k -v https://<server>:9398/api/backupServers -H "Authorization: Basic <session string> Content-Length: 0"
Which results in:

Code: Select all

* Connection #0 to host <server> left intact
{"FirstChanceExceptionMessage":null,"StackTrace":null,"Message":"Identity was not authenticated.","StatusCode":401,"Status":"Unauthorized"}\n
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Beginner Veeam API using curl

Post by chris.arceneaux »

Hi Ryan,

Step #5 in our documentation highlights the token that you use for further communication with the REST API after authentication.

Following the documentation, here's an example of the API call you asked about:

Code: Select all

curl --location --request GET 'https://em.arsano.lab:9398/api/backupServers' \
--header 'X-RestSvcSessionId: YzM4MjY0MzgtYjkxMC00ZWYxLWE5YTUtMjA0YjNhODc3NDI1'
Another recommendation I have that I think would help you would be to leverage Postman. It's free to use and I created a Postman collection for Enterprise Manager. With Postman, you can easily test API calls and then convert the API call into a programming language (like curl).
rwgustason
Novice
Posts: 9
Liked: 3 times
Joined: Aug 13, 2019 1:22 pm
Full Name: Ryan Gustason
Contact:

Re: Beginner Veeam API using curl

Post by rwgustason »

Thanks! That helped a lot!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest