Table objects

class servicenowpy.servicenow.Table

Represents ServiceNow’s Table API.

Parameters
  • table – The table name.

  • instance_url – ServiceNow instance URL”.

  • credentials – Tuple containing user and password, respectively.

get(api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a GET request to the instance table.

Parameters
  • api_version – API version, if API versioning is enabled.

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    All query parameters to the URL.

Return type

list

get_record(sys_id: str, api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a GET request to the instance table. Returns only one record, with the given sys_id.

Parameters
  • sys_id – Record unique ID.

  • api_version – API version, if API versioning is enabled.

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    All query parameters to the URL.

Return type

dict

get_record_by_number(number: str, api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a GET request to the instance table. Adds ‘number’ to the query parameters.

Parameters
  • number – Record number.

  • api_version – API version, if API versioning is enabled.

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    Other query parameters to the URL.

Return type

list

patch(sys_id: str, data: dict, api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a PATCH request to the instance table.

Parameters
  • sys_id – Record unique ID.

  • data – Fields and values to update in the record.

  • api_version – API version (if API versioning is enabled).

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    All query parameters to the URL.

Return type

dict

post(data: dict, api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a POST request to the instance table.

Parameters
  • data – Fields and values to the new record.

  • api_version – API version (if API versioning is enabled).

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    All query parameters to the URL.

Return type

dict

put(sys_id: str, data: dict, api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a PUT request to the instance table.

Parameters
  • sys_id – Record unique ID.

  • data – New values to the record.

  • api_version – API version (if API versioning is enabled).

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    All query parameters to the URL.

Return type

dict

delete(sys_id: str, api_version=None, headers={'Accept': 'application/json'}, verbose=False, **kwargs)

Sends a DELETE request to the instance table.

Parameters
  • sys_id – Record unique ID.

  • api_version – API version (if API versioning is enabled).

  • headers – Request headers.

  • verbose – If set to True, prints the full URL before it sends the request.

  • **kwargs

    All query parameters to the URL.

get_session(headers)

Returns a requests.Session object.

Parameters

headers – Request headers.

check_status_code(response: requests.models.Response, expected=200)

Checks if the given response status code is as expected. Raises a StatusCodeError if it is not.

Parameters
  • response – Response object.

  • expected – Expected status code.

make_url(api_version=None, sys_id=None, **kwargs)

Returns a complete url to send in the request.

Return type

str