Home > Tintri VMstore™ > Knowledge Base > How to use Tintri REST API via CURL

How to use Tintri REST API via CURL

Applies To

 

Product(s)

Version(s)

Tintri REST API

v310

Description

This article describes how to use the REST API via curl command to create a session on the VMstore and some example commands.

 

How-To

It is assumed that you know the following details:

  • The IP address or resolvable hostname of the VMstore
  • The IP address or resolvable hostname of vCenter or your hypervisor
  • Credentials to log in to the VMstore
  • You can use CURL from the command line 

 


Step 1: Create a login session on the VMstore using valid credentials and save the cookie as a file. This file will contain a valid JSESSIONID:

$ curl -i -X POST -H 'Content-Type: application/json' -d '{"username":"admin", "typeId":"com.tintri.api.rest.vcommon.dto.rbac.RestApiCredentials", "password":"<<PASSWORD>>"}' https://192.168.60.21/api/v310/session/login > cookie.txt 

 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   120    0     9  100   111     66    816 --:--:-- --:--:-- --:--:--   902

 

Note: if you receive a warning stating "SSL certificate problem" then you will need to use the -k option with curl (as I have included in the examples below).

 

Step 2: You can now issue commands against the VMstore using a valid session, by using the saved file from the previous step:

$ curl -k -i -X GET -H 'Content-Type: application/json' -b cookie.txt -d 'SnapshotResource.getSnapshots({'typeId': 'com.tintri.api.rest.v310.dto.SnapshotFilterSpec','name': 'Win2012AD'});' https://192.168.60.21/api/v310/snapshot 

 

Note: If you receive any errors regarding invalid sessions, then check your credentials in the login command above

Example: 

{"code":"ERR-API-0104","message":"Invalid session.","causeDetails":"","title":"Error","typeId":"com.tintri.api.rest.v310.dto.domain.beans.TintriError"}
 

Step 3: It is good practice to log out of your session when you have finished your actions:

$ curl -k -i -X GET -H 'Content-Type: application/json' -b cookie.txt https://192.168.60.21/api/v310/session/logout


HTTP/1.1 204 No Content
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Headers: Content-Type, Transfer-Encoding, Date, Server
Date: Tue, 28 Feb 2017 13:45:54 GMT
Server: Web server

 

 

Example 1:  Create a new VM from a snapshot ID (this is quite a long command with lots of parameters):

$ curl -k -i -X POST -H 'Content-Type: application/json' -b cookie.txt -d '{"typeId":"com.tintri.api.rest.v310.dto.domain.beans.vm.VirtualMachineCloneSpec",

> "snapshotId":"EF59A796-2A99-A43D-7DB1-A338F483C0E4-SST-000000000006F82B",

> "count":"1",

> "vmware":{"typeId":"com.tintri.api.rest.v310.dto.domain.beans.vm.VirtualMachineCloneSpec$VMwareCloneInfo", 
> "cloneVmName":"ANDREW-new-clone-from-snapshot", 
> "vCenterName":"192.168.60.207", 
> "datastoreName":"Tintri"}})' https://192.168.60.21/api/v310/vm 


RESULT: A VM is created in the 'Tintri' datastore and registered with vCenter:


HTTP/1.1 200 OK 
Access-Control-Allow-Origin: * 
Access-Control-Allow-Methods: GET, POST, DELETE, PUT 
Access-Control-Allow-Headers: Content-Type, Transfer-Encoding, Date, Server 
Content-Type: application/json; qs=1 
Transfer-Encoding: chunked 
Vary: Accept-Encoding 
Date: Tue, 28 Feb 2017 13:25:09 GMT 
Server: Web server 

{"typeId":"com.tintri.api.rest.v310.dto.Task","lastUpdatedTime":"2017-02-28T13:25:09.898Z","uuid":{"typeId":"com.tintri.api.rest.vcommon.dto.Uuid","entityTC":"JOB","uuid":"cloneSnapshot@02-28-01:24:53.573"},"targetType":"SNAPSHOT","progressPercent":100.0,"type":"CLONE","progressSecondsRemaining":0,"state":"SUCCESS","properties":[],"isCancelable":false,"progressDescription":"Successfully added 1 clones to vcenter inventory","progressError":false,"createDate":1488288293572,"jobDone":true} 
 

 

You will find the full VM clone spec listed in the API documentation linked below in the reference section. Other API specs are also detailed there. 

Viewing 2 of 2 comments: view all
Reviewed
Posted 18:03, 20 Mar 2017
approved
Posted 19:40, 21 Mar 2017
Viewing 2 of 2 comments: view all
You must to post a comment.
Last modified
10:54, 22 Apr 2017

Tags

Classifications

This page has no classifications.