wxc_sdk.rest module

REST session for Webex API requests

class wxc_sdk.rest.SingleError(*, description: str, errorCode: int = None)[source]

Bases: BaseModel

Representation of single error in the body of an HTTP error response from Webex

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

description: str
error_code: Optional[int]
property code: Optional[int]

Error code or None

Returns

error code

class wxc_sdk.rest.ErrorDetail(*, errorCode: int = None, message: str, errors: list[wxc_sdk.rest.SingleError], trackingId: str)[source]

Bases: ApiModel

Representation of error details in the body of an HTTP error response from Webex

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

error_code: Optional[int]
message: str

error message

errors: list[wxc_sdk.rest.SingleError]

list of errors; typically has a single entry

tracking_id: str

tracking ID of the request

property description: str

error description

property code: Optional[int]

error code

exception wxc_sdk.rest.RestError(msg: str, response: Response)[source]

Bases: HTTPError

A REST error

Initialize RequestException with request and response objects.

request: PreparedRequest
response: Response
property description: str

error description

property code: str

error code

class wxc_sdk.rest.RestSession(*, tokens: Tokens, concurrent_requests: int)[source]

Bases: Session

REST session used for API requests:
  • includes an Authorization header in reach request

  • implements retries on 429

  • loads deserializes JSON data if needed

BASE = 'https://webexapis.com/v1'

base URL for all Webex API requests

property access_token: str

access token used for all requests

Returns

access token

Return type

str

rest_get(*args, **kwargs) Union[str, dict][source]

GET request

Parameters
  • args

  • kwargs

Returns

deserialized JSON content or body text

rest_post(*args, **kwargs) Union[str, dict][source]

POST request

Parameters
  • args

  • kwargs

Returns

deserialized JSON content or body text

rest_put(*args, **kwargs) Union[str, dict][source]

PUT request

Parameters
  • args

  • kwargs

Returns

deserialized JSON content or body text

rest_delete(*args, **kwargs) None[source]

DELETE request

Parameters
  • args

  • kwargs

rest_patch(*args, **kwargs) Union[str, dict][source]

PATCH request

Parameters
  • args

  • kwargs

follow_pagination(url: str, model: Optional[Type[ApiModel]] = None, params: Optional[dict] = None, item_key: Optional[str] = None, **kwargs) Generator[ApiModel, None, None][source]

Handling RFC5988 pagination of list requests. Generator of parsed objects

Parameters
  • url (str) – start url for 1st GET

  • model (ApiModel) – data type to return

  • params (Optional[dict]) – URL parameters, optional

  • item_key (str) – key to list of values

Returns

yields parsed objects

wxc_sdk.rest.dump_response(response: Response, file: Optional[TextIOBase] = None, dump_log: Optional[Logger] = None, diff_ns: Optional[int] = None)[source]

Dump response object to log file

Parameters
  • response – HTTP request response

  • file (TextIOBase) – stream to dump to

  • dump_log (logging.Logger) – logger to dump to

  • diff_ns (int) – time the request took (in ns)