bunq / sdk_python

Python SDK for bunq API
MIT License
106 stars 25 forks source link

Missing a callback sample #15

Closed CharlPels closed 7 years ago

CharlPels commented 7 years ago

Is it possible to ad a callback code sample. The webserver i can configure my self etc but love to have a sample on how to setup the callback so for example when a pin or other transaction happens i can react on it.

Not an issue just a request :-)

OGKevin commented 7 years ago

Hey @CharlPels

Here an example to set a call back to UserPerson 👍


from bunq.sdk.model.generated.endpoint import UserPerson
from bunq.sdk.model.generated.object_ import NotificationFilter
from bunq.sdk.context import ApiContext

ctx = ApiContext.restore()
USER_ID = 400

filter_ = NotificationFilter('URL', 'myurl.com', 'BILLING')

request_body = {
    UserPerson.FIELD_NOTIFICATION_FILTERS: filter_
}

UserPerson.update(ctx, request_body, USER_ID)

Let me know if this is what you were looking for 😄.

CharlPels commented 7 years ago

No luck, get an error bunq.sdk.exception.ApiException: HTTP Response Code: 400 Invalid type for field "notification_filters" (expected ARRAY containing STRUCT).

filter i use is filter_ = NotificationFilter('URL', 'https://bunqsample.azurewebsites.net/api1', 'BILLING')

dnl-blkv commented 7 years ago

@OGKevin @CharlPels I believe it should have been:

from bunq.sdk.model.generated.endpoint import UserPerson
from bunq.sdk.model.generated.object_ import NotificationFilter
from bunq.sdk.context import ApiContext

ctx = ApiContext.restore()
USER_ID = 400

filters = [NotificationFilter('URL', 'myurl.com', 'BILLING')]

request_body = {
    UserPerson.FIELD_NOTIFICATION_FILTERS: filters
}

UserPerson.update(ctx, request_body, USER_ID)

Source: https://doc.bunq.com/api/1/call/user-person/method/put

@CharlPels please let me know if this doesn't work. I did not run the code myself yet - will do so as the first thing tomorrow, if it still doesn't work :)

OGKevin commented 7 years ago

@CharlPels 😁 I forgot to array it indeed @dnl-blkv example looks to be the correct example 😉

CharlPels commented 7 years ago

It is working now, and now how to remove a callback endpoint would also be nice to know :-)

OGKevin commented 7 years ago

@CharlPels To remove a callback you can do this:

filters = [NotificationFilter('PUSH', None, 'BILLING')]

You can read more about this here: https://together.bunq.com/topic/unregister-callback-webhook#comment-7926

UserPerson.update(ctx, request_body, USER_ID)

Will return an id as shown here: https://doc.bunq.com/api/1/call/user-company/method/put

If you get this id, means that the request came back with status 200 (which means everything went successful)

Afterwards depending on the category you've chosen, which are listed here: https://doc.bunq.com/api/1/page/callbacks

You will get a POST request to the url you defined.

OGKevin commented 7 years ago

Closing the issue, feel free to comment afterwards.