Skip to content

Instantly share code, notes, and snippets.

@basst85
Created August 13, 2019 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basst85/e559559b34dfcd81a5d047a04c77d05d to your computer and use it in GitHub Desktop.
Save basst85/e559559b34dfcd81a5d047a04c77d05d to your computer and use it in GitHub Desktop.
Add callback URL to bunq user
#!/usr/bin/python3
import warnings
from bunq.sdk import context
from bunq.sdk.json import converter
from bunq.sdk.client import Pagination
from bunq.sdk.context import ApiContext
from bunq.sdk.context import ApiEnvironmentType
from bunq.sdk.context import BunqContext
from bunq.sdk.model.generated import endpoint
from bunq.sdk.model.generated.object_ import Pointer, Amount, NotificationFilter
warnings.filterwarnings("ignore")
_API_KEY = '<Your API KEY>'
_DEVICE_DESCRIPTION = 'TestPython'
_CALLBACL_URL = 'https://webhook.site/This_is_an_exaple'
_CONFIG_FILE_LOCATION = './bunq_sandbox.conf'
def run():
ApiContext(
ApiEnvironmentType.SANDBOX,
_API_KEY,
_DEVICE_DESCRIPTION).save(_CONFIG_FILE_LOCATION)
api_context = ApiContext.restore(_CONFIG_FILE_LOCATION)
api_context.ensure_session_active()
api_context.save(_CONFIG_FILE_LOCATION)
BunqContext.load_api_context(api_context)
user = endpoint.User.get().value
all_notification_filter_updated = []
all_user_alias = user.UserPerson.alias
# Show all aliases for user
for alias in all_user_alias:
print(f'''{alias.value}''')
# Add callback URLs with type MUTATION
all_notification_filter_updated.append(
NotificationFilter('URL', _CALLBACL_URL, 'MUTATION')
)
user.UserPerson.update(notification_filters=all_notification_filter_updated)
# Send an empty array to remove all filters:
# user.UserPerson.update(notification_filters=[])
notification_filters = user.UserPerson.notification_filters
for filter in notification_filters:
print(f'''Method: {filter.notification_delivery_method}, Target: {filter.notification_target}, Category: {filter.category}''')
# Run it only if called from the command line
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment