apamax.eplapplications.connection

C8yConnection

class apamax.eplapplications.connection.C8yConnection(url, username, password)[source]

Bases: object

Simple object to create connection to Cumulocity IoT and perform REST requests.

Parameters
  • url – The Cumulocity IoT tenant url.

  • username – The username.

  • password – The password.

do_get(path, params=None, headers=None, jsonResp=True)[source]

Perform GET request.

Parameters
  • path – The path to the resource.

  • params – The query params.

  • headers – The headers.

  • jsonResp – Response is JSON.

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 request method.

Returns

Response body string.

request(method, path, body=None, headers=None, useLocationHeaderPostResp=True)[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.

Returns

Body of the response. In case of POST request, id of the resource specified by the Location header.