apamax.eplapplications.connection¶
C8yConnection¶
- class apamax.eplapplications.connection.C8yConnection(url, username, password, timeoutSecs=None)[source]¶
Bases:
objectSimple object to create connection to Cumulocity and perform REST requests.
- Parameters:
url – The Cumulocity tenant url.
username – The username.
password – The password.
timeoutSecs – The default timeout (in seconds) for each socket operation performed while making a REST request using this connection. Individual requests can override this. If neither is specified, Python’s default socket timeout applies.
- do_get(path, params=None, headers=None, jsonResp=True, timeoutSecs=None)[source]¶
Perform GET request.
- Parameters:
path – The path to the resource.
params – The query params.
headers – The headers.
jsonResp – Response is JSON.
timeoutSecs – The timeout (in seconds) for each socket operation performed while making this request. If not specified, the default timeout of this connection is used, if it has one.
- Returns:
The body of the response. If JSON output is expected then parse the JSON string to python object.
- do_request_json(method, path, body, headers=None, **kwargs)[source]¶
Perform REST request (POST/GET mainly) with JSON body.
- Parameters:
method – The REST method.
path – The path to resource.
body – The JSON body.
headers – The headers.
kwargs – Any additional kwargs to pass to the
requestmethod.
- Returns:
Response body string.
- request(method, path, body=None, headers=None, useLocationHeaderPostResp=True, timeoutSecs=None)[source]¶
Perform an HTTP request. In case of POST request, return the id of the created resource.
- Parameters:
method – The method.
path – The path of the resource.
body – The body for the request.
headers – The headers for the request.
useLocationHeaderPostResp – Whether or not to attempt to use the ‘Location’ header in the response to return the ID of the resource that was created by a POST request.
timeoutSecs – The timeout (in seconds) for each socket operation performed while making this request. If not specified, the default timeout of this connection is used, if it has one.
- Returns:
Body of the response. In case of POST request, id of the resource specified by the Location header.