CloudConnect RestAPI Using Curl and Python

This article is for those who are interesting on working with curl and python to run REST API commands against the CloudConnect solution.

In the code below you can find a general process and some functions.
In addition to that, there is a description of each function in the comments.

You always can refer to 'REST API Docs' for more details under the following link from your CloudConnect web interface:


Python

For using the CloudConnect REST API using Python, you can find the attached sample script.

The script automates a single flow that a user can run.

The flow includes creation of a check-in connection and create the first version.

* Note- You should modify some of the properties based on your own environment


Curl


# First, we should create a file called session.json which includes your WEB credential:
{
"user":
{
"login":"admin",
"password":"changeme"
}
}


# Then, we should generate a new session for communicating with the CloudConnect server

$ curl -vX POST https://10.11.184.137/elcc_api/sessions --insecure -d @session.json --header "Content-Type: application/json"
* About to connect() to 10.11.184.137 port 443 (#0)
*   Trying 10.11.184.137...
* Connected to 10.11.184.137 (10.11.184.137) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_DHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*   subject: CN=127.0.0.1,O=elastifile_mOLMnpTG
*   start date: Nov 08 11:16:56 2018 GMT
*   expire date: Nov 05 11:16:56 2028 GMT
*   common name: 127.0.0.1
*   issuer: CN=127.0.0.1,O=elastifile_mOLMnpTG
> POST /elcc_api/sessions HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 10.11.184.137
> Accept: */*
> Content-Type: application/json
> Content-Length: 48
>
* upload completely sent off: 48 out of 48 bytes
< HTTP/1.1 200 OK
< Date: Mon, 26 Nov 2018 07:31:57 GMT
< Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips Phusion_Passenger/5.0.15
< Cache-Control: max-age=0, private, must-revalidate
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Runtime: 0.080431
< X-Request-Id: 4853f430-dc91-401f-ac61-4873672e20c0
< X-Powered-By: Phusion Passenger 5.0.15
< Set-Cookie: XSRF-TOKEN=1I%2BGZcLU%2BEeiZAUfFeHfvtUSAJp1goCfYckaRAwD2szQJcvYMd6hNpMZ085tFCza9p4C8lZfdFXrTd16O2eA4w%3D%3D; path=/
< Set-Cookie: _ccweb_session=eXlxQUxydVgxSVhwb0lDOFRiUEZPODBFRE5XZ05NUXRRQit3aC9YM0w4Y2JhY0hGelBKaW1HYmxRdUtyVHZHZ0s1WlQzcE0wc3ZGVTZnRk9aMnF1dlllUjRmWU5VQUxoZ1dTc3p4eEdTb0NENVNCUStNeE16RHRzTVJPa0kveGMzUFkrZ2FBWDNvZUE0OFhxRlRHcmtEMTlxRXFvYkVoVjR6dlYwM0ZlS0JRRDdud3JlMWpDQlptRjU3eEpiNWtuQ3dpMUdUZHBDdkM3T0c2WnZ6NHJZaVRnTDFLdE13b0phWDh3SnB3amM1dWhDdk91VXNCK3NKaE41Tmk1amlOQi0tU2lrNWdYWjJVYWhpa21aMytlVmtLQT09--709cce5cebd9668ea5adfa2bd2f4697b6a4a113f; path=/; HttpOnly
< ETag: W/"2662cc67e6a7a99e96151216624ee026"
< Status: 200 OK
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
<
* Connection #0 to host 10.11.184.137 left intact
{"info":"Logged in","user":{"id":1,"login":"admin","admin":true,"first_name":"Super","surname":"Admin","email":"admin@example.com","created_at":"2018-11-08T11:16:55.000Z","updated_at":"2018-11-26T07:31:58.003Z"}}|-- snirz@buildvm:buildvm-snirz:~/cc_api --|


# Using the cookie we got in the session creation, we can perform all the other commands such as GET, POST, PUT and DELETE

$ curl -vX GET https://10.11.184.137/elcc_api/connections --insecure --header "Content-Type: application/json" -b _ccweb_session=eXlxQUxydVgxSVhwb0lDOFRiUEZPODBFRE5XZ05NUXRRQit3aC9YM0w4Y2JhY0hGelBKaW1HYmxRdUtyVHZHZ0s1WlQzcE0wc3ZGVTZnRk9aMnF1dlllUjRmWU5VQUxoZ1dTc3p4eEdTb0NENVNCUStNeE16RHRzTVJPa0kveGMzUFkrZ2FBWDNvZUE0OFhxRlRHcmtEMTlxRXFvYkVoVjR6dlYwM0ZlS0JRRDdud3JlMWpDQlptRjU3eEpiNWtuQ3dpMUdUZHBDdkM3T0c2WnZ6NHJZaVRnTDFLdE13b0phWDh3SnB3amM1dWhDdk91VXNCK3NKaE41Tmk1amlOQi0tU2lrNWdYWjJVYWhpa21aMytlVmtLQT09--709cce5cebd9668ea5adfa2bd2f4697b6a4a113f

[{"id":1,"name":"first_conn","ccstore_ref":"conn_bucket--gcp-778","nfsserver":null,"nfsexport":null,"fs_path":"/tmp","direction":"direction_upload","checkout_absent_policy":"absent_delete","checkout_modified_policy":"modified_keep_existing","created_at":"2018-11-26T07:20:34.000Z","updated_at":"2018-11-26T07:20:34.000Z","ccstore":{"ccstore_uuid":"c79f243c-c761-42a8-9781-67cf4fae34b2","user_password":"XXXX","ccstore_ref":"conn_bucket--gcp-778","object_store_api":"gc","bucket_name":"conn_bucket","user_key":"","object_store":"gcp","cred_path":"XXXX","endpoint":"","format_version":1015,"compression_method":"auto","bucket_tag":"","region":"eu","block_size":2097152,"ccstore_name":"conn_bucket--gcp-778","owner_service_uuid":"10714d98-84f1-46fd-8ddd-9acd0960303b","hash_type":"SHA-256"}}]|




S
Snir is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.