Lumen help

Managing API sessions for Edge Private Cloud

Use an API call to create an authentication token and API session. Basic authentication requires login credentials and the API endpoints available depend on your permissions.

Use LPC on VCF to create an authorization token which is then used to create API sessions. API sessions have restrictions based on user permissions.

Retrieve an API session to continue working in that session or check information about the session.

End an API session when you are finished. If the token is still valid, you can create a new session using that existing token and continue working.

Creating an API session with basic authentication

To create an API session with basic authentication:

                https://{cloud_site_id}.vcf.ctl.io/api/sessions
            
                https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions
            

                $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json;version=36.2")
$headers.Add("Authorization", "Basic {base64encodedcredentials}")

$response = Invoke-RestMethod 'https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions' -Method 'POST' -Headers $headers -ResponseHeadersVariable responseHeaders 
$response | ConvertTo-Json
$accesstoken = $responseHeaders.'X-VMWARE-VCLOUD-ACCESS-TOKEN'
            

                import requests

url = "https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions"

payload = {}
headers = {
  'Accept': 'application/json;version=36.2',
  'Authorization': 'Basic {base64encodedcredentials}'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
accesstoken = response.headers['X-VMWARE-VCLOUD-ACCESS-TOKEN']

            

                import requests

url = "https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions"

payload = {}
headers = {
  'Accept': 'application/json;version=36.2',
  'Authorization': 'Basic {base64encodedcredentials}'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
accesstoken = response.headers['X-VMWARE-VCLOUD-ACCESS-TOKEN']

            

Creating an API session with an authentication token

                https://{cloud_site_id}.vcf.ctl.io/oauth/tenant/{{org}}/token
            

                $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/x-www-form-urlencoded")

$body = "grant_type=refresh_token&refresh_token={api_access_token_from_vcd_ui}"

$response = Invoke-RestMethod 'https://{cloud_site_id}.vcf.ctl.io/oauth/tenant/{org_site_id}/token' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

$accesstoken=$response.access_token
            

                import requests
import json

url = "https://{cloud_site_id}.vcf.ctl.io/oauth/tenant/{org_site_id}/token"

payload = 'grant_type=refresh_token&refresh_token={vcloud_user_api_access_token}'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

json.loads(response.text)

accesstoken=json.loads(response.text)['access_token']

print(response.text)

            

                import http.client
import json

conn = http.client.HTTPSConnection("{cloud_site_id}.vcf.ctl.io")
payload = 'grant_type=refresh_token&refresh_token={vcloud_user_api_access_token}'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}
conn.request("POST", "/oauth/tenant/{org_site_id}/token", payload, headers)
res = conn.getresponse()
data = res.read()

accesstoken = json.loads(data.decode("utf-8"))['access_token']
print(data.decode("utf-8"))

            

Retrieving an API session

                1.0.0/sessions/current
            

                $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json;version=36.2")
$headers.Add("Authorization", "Bearer {bearer_token_recieved_from_new_session}")

$response = Invoke-RestMethod 'https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions/current' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
            

                import requests

url = "https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions/current"

payload = {}
headers = {
  'Accept': 'application/json;version=36.2',
  'Authorization': 'Bearer {bearer_token_recieved_from_new_session}'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

            

                import http.client

conn = http.client.HTTPSConnection("{cloud_site_id}.vcf.ctl.io")
payload = ''
headers = {
  'Accept': 'application/json;version=36.2',
  'Authorization': 'Bearer {bearer_token_recieved_from_new_session}'
}
conn.request("GET", "/cloudapi/1.0.0/sessions/current", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
            

Ending an API session

                https://{cloud_site_id}.vcf.ctl.io/oauth/tenant/{{org}}/token
            

                $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json;version=36.2")
$headers.Add("Authorization", "Bearer {bearer_token_recieved_from_new_session}")

$response = Invoke-RestMethod 'https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions/current' -Method 'DELETE' -Headers $headers
$response | ConvertTo-Json
            

                import requests

url = "https://{cloud_site_id}.vcf.ctl.io/cloudapi/1.0.0/sessions/current"

payload = {}
headers = {
  'Accept': 'application/json;version=36.2',
  'Authorization': 'Bearer {bearer_token_recieved_from_new_session}'
}

response = requests.request("DELETE", url, headers=headers, data=payload)

print(response.text)
            

                import http.client

conn = http.client.HTTPSConnection("{cloud_site_id}.vcf.ctl.io")
payload = ''
headers = {
  'Accept': 'application/json;version=36.2',
  'Authorization': 'Bearer {bearer_token_recieved_from_new_session}'
}
conn.request("DELETE", "/cloudapi/1.0.0/sessions/current", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))