|
| 1 | +# bunq Java SDK |
| 2 | +Version 0.9.0 **BETA** |
| 3 | + |
| 4 | +## Installation |
| 5 | +In the root of your project, being in the correct virtual environment, run: |
| 6 | +```shell |
| 7 | +(bunq_sdk_python) $ pip install bunq_sdk && pip freeze > requirements.txt |
| 8 | +``` |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +### Creating an API context |
| 13 | +In order to start making calls with the bunq API, you must first register your API key and device, |
| 14 | +and create a session. In the SDKs, we group these actions and call it "creating an API context". The |
| 15 | +context can be created by using the following code snippet: |
| 16 | + |
| 17 | +``` |
| 18 | +apiContext = context.ApiContext(ENVIRONMENT_TYPE, API_KEY, |
| 19 | + DEVICE_DESCRIPTION); |
| 20 | +apiContext.save(API_CONTEXT_FILE_PATH); |
| 21 | +``` |
| 22 | + |
| 23 | +#### Example |
| 24 | +See [`api_context_save_example.py`](./examples/api_context_save_example.py) |
| 25 | + |
| 26 | +The API context can then be saved with: |
| 27 | + |
| 28 | +#### Safety considerations |
| 29 | +The file storing the context details (i.e. `bunq.conf`) is a key to your account. Anyone having |
| 30 | +access to it is able to perform any Public API actions with your account. Therefore, we recommend |
| 31 | +choosing a truly safe place to store it. |
| 32 | + |
| 33 | +### Making API calls |
| 34 | +There is a class for each endpoint. Each class has functions for each supported action. These |
| 35 | +actions can be `create`, `get`, `update`, `delete` and `list`. |
| 36 | + |
| 37 | +Sometimes API calls have dependencies, for instance `MonetaryAccount`. Making changes to a monetary |
| 38 | +account always also needs a reference to a `User`. These dependencies are required as arguments when |
| 39 | +performing API calls. Take a look at [doc.bunq.com](https://doc.bunq.com) for the full |
| 40 | +documentation. |
| 41 | + |
| 42 | +#### Creating objects |
| 43 | +Creating objects through the API requires an `ApiContext`, a `requestMap` and identifiers of all |
| 44 | +dependencies (such as User ID required for accessing a Monetary Account). Optionally, custom headers |
| 45 | +can be passed to requests. |
| 46 | + |
| 47 | + |
| 48 | +``` |
| 49 | +request_map = { |
| 50 | + generated.Payment.FIELD_AMOUNT: object_.Amount( |
| 51 | + _PAYMENT_AMOUNT, |
| 52 | + _PAYMENT_CURRENCY |
| 53 | + ), |
| 54 | + generated.Payment.FIELD_COUNTERPARTY_ALIAS: object_.Pointer( |
| 55 | + _COUNTERPARTY_POINTER_TYPE, |
| 56 | + _COUNTERPARTY_EMAIL |
| 57 | + ), |
| 58 | + generated.Payment.FIELD_DESCRIPTION: _PAYMENT_DESCRIPTION, |
| 59 | +} |
| 60 | +
|
| 61 | +payment_id = generated.Payment.create( |
| 62 | + api_context, |
| 63 | + request_map, |
| 64 | + _USER_ITEM_ID, |
| 65 | + _MONETARY_ACCOUNT_ITEM_ID |
| 66 | +) |
| 67 | +``` |
| 68 | + |
| 69 | +##### Example |
| 70 | +See [`PaymentExample.py`](./examples/payment_example.py) |
| 71 | + |
| 72 | +#### Reading objects |
| 73 | +Reading objects through the API requires an `ApiContext`, identifiers of all dependencies (such as |
| 74 | +User ID required for accessing a Monetary Account), and the identifier of the object to read (ID or |
| 75 | +UUID) Optionally, custom headers can be passed to requests. |
| 76 | + |
| 77 | +This type of calls always returns a model. |
| 78 | + |
| 79 | +``` |
| 80 | +monetary_account = generated.MonetaryAccountBank.get( |
| 81 | + api_context, |
| 82 | + _USER_ITEM_ID, |
| 83 | + _MONETARY_ACCOUNT_ITEM_ID |
| 84 | +) |
| 85 | +``` |
| 86 | + |
| 87 | +##### Example |
| 88 | +See [`MonetaryAccountExample.py`](./examples/monetary_account_example.py) |
| 89 | + |
| 90 | +#### Updating objects |
| 91 | +Updating objects through the API goes the same way as creating objects, except that also the object to update identifier |
| 92 | +(ID or UUID) is needed. |
| 93 | + |
| 94 | +``` |
| 95 | +request_update_map = { |
| 96 | + generated.RequestInquiry.FIELD_STATUS: _STATUS_REVOKED, |
| 97 | +} |
| 98 | +generated.RequestInquiry.update( |
| 99 | + api_context, |
| 100 | + request_update_map, |
| 101 | + _USER_ITEM_ID, |
| 102 | + _MONETARY_ACCOUNT_ITEM_ID, |
| 103 | + request_id |
| 104 | +).to_json() |
| 105 | +``` |
| 106 | + |
| 107 | +##### Example |
| 108 | +See [`RequestExample.py`](./examples/request_example.py) |
| 109 | + |
| 110 | +#### Deleting objects |
| 111 | +Deleting objects through the API requires an `ApiContext`, identifiers of all dependencies (such as User ID required for |
| 112 | +accessing a Monetary Account), and the identifier of the object to delete (ID or UUID) Optionally, custom headers can be |
| 113 | +passed to requests. |
| 114 | + |
| 115 | +``` |
| 116 | +generated.CustomerStatementExport.delete(apiContext, userId, monetaryAccountId, customerStatementId); |
| 117 | +``` |
| 118 | + |
| 119 | +##### Example |
| 120 | +See [`CustomerStatementExportExample.py`](./examples/customer_statement_export_example.py) |
| 121 | + |
| 122 | +#### Listing objects |
| 123 | +Listing objects through the API requires an `ApiContext` and identifiers of all dependencies (such as User ID required |
| 124 | +for accessing a Monetary Account). Optionally, custom headers can be passed to requests. |
| 125 | + |
| 126 | +``` |
| 127 | +users = generated.User.list(api_context) |
| 128 | +``` |
| 129 | + |
| 130 | +##### Example |
| 131 | +See [`UserListExample.py`](./examples/user_list_example.py) |
0 commit comments