pysnow.Request — Creates a new request object¶
-
class
pysnow.Request(method, table, **kwargs)[source]¶ Takes arguments used to perform a HTTP request
Parameters: - method – HTTP request method
- table – table to operate on
-
last_response¶ Return _last_response after making sure an inner
requests.requesthas been performedRaise: NoRequestExecuted: If no request has been executed Returns: last response
-
count¶ Returns the number of records the query would yield
-
status_code¶ Return last_response.status_code after making sure an inner
requests.requesthas been performedReturns: status_code of last_response
-
get_multiple(fields=[], limit=None, order_by=[], offset=None)[source]¶ Wrapper method that takes whatever was returned by the _all_inner() generators and chains it in one result
The response can be sorted by passing a list of fields to order_by.
Example: get_multiple(order_by=[‘category’, ‘-created_on’]) would sort the category field in ascending order, with a secondary sort by created_on in descending order.
Parameters: - fields – List of fields to return in the result
- limit – Limits the number of records returned
- order_by – Sort response based on certain fields
- offset – A number of records to skip before returning records (for pagination)
Returns: Iterable chain object
-
get_one(fields=[])[source]¶ Convenience function for queries returning only one result. Validates response before returning.
Parameters: fields – List of fields to return in the result
Raise: MultipleResults: if more than one match is found Returns: Record content
-
insert(payload)[source]¶ Inserts a new record with the payload passed as an argument
Parameters: payload – The record to create (dict) Returns: Created record
-
delete()[source]¶ Deletes the queried record and returns response content after response validation
Raise: NoResults: if query returned no results NotImplementedError: if query returned more than one result (currently not supported) Returns: Delete response content (Generally always {‘Success’: True})
-
update(payload)[source]¶ Updates the queried record with
payloadand returns the updated record after validating the responseParameters: payload – Payload to update the record with
Raise: NoResults: if query returned no results MultipleResults: if query returned more than one result (currently not supported) Returns: The updated record
-
clone(reset_fields=[])[source]¶ Clones the queried record
Parameters: reset_fields – Fields to reset
Raise: NoResults: if query returned no results MultipleResults: if query returned more than one result (currently not supported) UnexpectedResponse: informs the user about what likely went wrong Returns: The cloned record
-
attach(file)[source]¶ Attaches the queried record with
fileand returns the response after validating the responseParameters: file – File to attach to the record
Raise: NoResults: if query returned no results MultipleResults: if query returned more than one result (currently not supported) Returns: The attachment record metadata
-
exception
pysnow.exceptions.UnexpectedResponse(code_expected, code_actual, http_method, error_summary, error_details)[source]¶ Informs the user about what went wrong when interfacing with the API
Parameters: - code_expected – Expected HTTP status code
- code_actual – Actual HTTP status code
- http_method – HTTP method used
- error_summary – Summary of what went wrong
- error_details – Details about the error