projectal.entities.webhook
1from projectal import api 2from projectal.entity import Entity 3 4 5class Webhook(Entity): 6 """ 7 Implementation of the [Webhook](https://projectal.com/docs/latest/#tag/Webhook) API. 8 """ 9 10 _path = "webhook" 11 _name = "webhook" 12 13 @classmethod 14 def update(cls, entities): 15 # The webhook API differs from the rest of the system. We need to send some 16 # mandatory fields over even if they haven't changed. Do this by faking 17 # the change history to always include the required fields. 18 if isinstance(entities, dict): 19 e_list = [entities] 20 else: 21 e_list = entities 22 23 for e in e_list: 24 if isinstance(e, Webhook): 25 e._Entity__old.pop("entity", None) 26 e._Entity__old.pop("action", None) 27 e._Entity__old.pop("url", None) 28 return super(Webhook, cls).update(e_list) 29 30 @classmethod 31 def list(cls, start=0, limit=101, ksort="entity", order="asc"): 32 """ 33 Get a list of registered webhooks. 34 35 Optionally specify a range for pagination. 36 """ 37 url = "/api/webhook/list?start={}&limit={}&ksort={}&order={}".format( 38 start, limit, ksort, order 39 ) 40 return api.get(url) 41 42 @classmethod 43 def list_events(cls, **kwargs): 44 """ 45 Get a list of webhook events. 46 Use parameter format=False to return eventTime as UTC timestamp. 47 """ 48 49 url = "/api/webhookevent/list" 50 51 params = [f"{k}={v}" for k, v in kwargs.items()] 52 if len(params) > 0: 53 url += "?" + "&".join(params) 54 response = api.get(url) 55 return response
6class Webhook(Entity): 7 """ 8 Implementation of the [Webhook](https://projectal.com/docs/latest/#tag/Webhook) API. 9 """ 10 11 _path = "webhook" 12 _name = "webhook" 13 14 @classmethod 15 def update(cls, entities): 16 # The webhook API differs from the rest of the system. We need to send some 17 # mandatory fields over even if they haven't changed. Do this by faking 18 # the change history to always include the required fields. 19 if isinstance(entities, dict): 20 e_list = [entities] 21 else: 22 e_list = entities 23 24 for e in e_list: 25 if isinstance(e, Webhook): 26 e._Entity__old.pop("entity", None) 27 e._Entity__old.pop("action", None) 28 e._Entity__old.pop("url", None) 29 return super(Webhook, cls).update(e_list) 30 31 @classmethod 32 def list(cls, start=0, limit=101, ksort="entity", order="asc"): 33 """ 34 Get a list of registered webhooks. 35 36 Optionally specify a range for pagination. 37 """ 38 url = "/api/webhook/list?start={}&limit={}&ksort={}&order={}".format( 39 start, limit, ksort, order 40 ) 41 return api.get(url) 42 43 @classmethod 44 def list_events(cls, **kwargs): 45 """ 46 Get a list of webhook events. 47 Use parameter format=False to return eventTime as UTC timestamp. 48 """ 49 50 url = "/api/webhookevent/list" 51 52 params = [f"{k}={v}" for k, v in kwargs.items()] 53 if len(params) > 0: 54 url += "?" + "&".join(params) 55 response = api.get(url) 56 return response
Implementation of the Webhook API.
14 @classmethod 15 def update(cls, entities): 16 # The webhook API differs from the rest of the system. We need to send some 17 # mandatory fields over even if they haven't changed. Do this by faking 18 # the change history to always include the required fields. 19 if isinstance(entities, dict): 20 e_list = [entities] 21 else: 22 e_list = entities 23 24 for e in e_list: 25 if isinstance(e, Webhook): 26 e._Entity__old.pop("entity", None) 27 e._Entity__old.pop("action", None) 28 e._Entity__old.pop("url", None) 29 return super(Webhook, cls).update(e_list)
Save one or more entities of the same type. The entity type is determined by the subclass calling this method. Only the fields that have been modifier will be sent to the server as part of the request.
entities
: Can be a dict
to update a single entity,
or a list of dict
s to update many entities in bulk.
'batch_linking': Enabled by default, batches any link updates required into composite API requests. If disabled a request will be executed for each link update. Recommended to leave enabled to increase performance.
Returns True
if all entities update successfully.
# Example usage:
rebate = projectal.Rebate.create({'name': 'Rebate2022', 'rebate': 0.2})
rebate['name'] = 'Rebate2024'
projectal.Rebate.update(rebate)
# Returns True. New rebate name has been saved.
31 @classmethod 32 def list(cls, start=0, limit=101, ksort="entity", order="asc"): 33 """ 34 Get a list of registered webhooks. 35 36 Optionally specify a range for pagination. 37 """ 38 url = "/api/webhook/list?start={}&limit={}&ksort={}&order={}".format( 39 start, limit, ksort, order 40 ) 41 return api.get(url)
Get a list of registered webhooks.
Optionally specify a range for pagination.
43 @classmethod 44 def list_events(cls, **kwargs): 45 """ 46 Get a list of webhook events. 47 Use parameter format=False to return eventTime as UTC timestamp. 48 """ 49 50 url = "/api/webhookevent/list" 51 52 params = [f"{k}={v}" for k, v in kwargs.items()] 53 if len(params) > 0: 54 url += "?" + "&".join(params) 55 response = api.get(url) 56 return response
Get a list of webhook events. Use parameter format=False to return eventTime as UTC timestamp.
Inherited Members
- projectal.entity.Entity
- get
- delete
- history
- create
- save
- clone
- match
- match_startswith
- match_endswith
- match_one
- match_startswith_one
- match_endswith_one
- search
- query
- profile_get
- profile_set
- changes
- set_readonly
- get_link_definitions
- entity_name
- builtins.dict
- setdefault
- pop
- popitem
- keys
- items
- values
- fromkeys
- clear
- copy