### GET /installation Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation Retrieves the public key of the server. ```APIDOC ## GET /installation ### Description This endpoint allows you to retrieve the public key of the server. This public key can be used for encrypting data that needs to be sent to the server securely. ### Method GET ### Endpoint /installation ### Parameters None ### Response #### Success Response (200) - **server_public_key** (string) - The public key of the server. #### Response Example ```json { "server_public_key": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA...\n-----END PUBLIC KEY-----" } ``` ``` -------------------------------- ### POST /installation Source: https://doc.bunq.com/installation Creates a new installation. This process is closely tied to creating a device and session. Refer to the tutorial for a comprehensive guide. ```APIDOC ## POST /installation ### Description Creates a new installation. This process is closely tied to creating a device and session. Refer to the tutorial for a comprehensive guide. ### Method POST ### Endpoint /installation ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Refer to the provided OpenAPI specification for request body details) ### Request Example (Refer to the provided OpenAPI specification for request example details) ### Response #### Success Response (200) (Refer to the provided OpenAPI specification for success response details) #### Response Example (Refer to the provided OpenAPI specification for response example details) ``` -------------------------------- ### GET /installation Source: https://doc.bunq.com/installation Retrieves a list of existing installations. This operation is part of managing devices and sessions. ```APIDOC ## GET /installation ### Description Retrieves a list of existing installations. This operation is part of managing devices and sessions. ### Method GET ### Endpoint /installation ### Parameters #### Path Parameters None #### Query Parameters (Refer to the provided OpenAPI specification for query parameters) #### Request Body None ### Request Example None ### Response #### Success Response (200) (Refer to the provided OpenAPI specification for success response details) #### Response Example (Refer to the provided OpenAPI specification for response example details) ``` -------------------------------- ### Install Dependencies with Python Setup Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/python/tests Installs all the required dependencies for the Bunq SDK Python project using the `setup.py` script. This command should be executed in the root directory of the project. ```powershell python setup.py install ``` -------------------------------- ### GET /installation/{installationID}/server-public-key Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation Retrieves the ServerPublicKey for a specific Installation. This is useful for re-requesting the public key associated with an installation ID. ```APIDOC ## GET /installation/{installationID}/server-public-key ### Description Show the ServerPublicKey for this Installation. ### Method GET ### Endpoint /installation/{installationID}/server-public-key ### Parameters #### Path Parameters - **installationID** (integer) - Required - The ID of the installation for which to retrieve the server public key. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **server_public_key** (string) - The server's public key for this Installation. #### Response Example ```json [ { "server_public_key": "your_server_public_key_here" } ] ``` #### Error Response (400) - **error_description** (string) - The error description in English. - **error_description_translated** (string) - The error description translated to the user's language. ``` -------------------------------- ### Example: Making a Payment with Bunq SDK Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/python/usage This example shows how to create a payment using the bunq SDK. It involves loading an existing API context, creating an `AmountObject` and `PointerObject` for the recipient, and then using `PaymentApiObject.create` to initiate the payment. ```python from bunq.sdk.context.api_context import ApiContext from bunq.sdk.context.bunq_context import BunqContext from bunq.sdk.model.generated.endpoint import PaymentApiObject from bunq.sdk.model.generated.object_ import AmountObject, PointerObject # Load API context api_context = ApiContext.restore("bunq_api_context.conf") BunqContext.load_api_context(api_context) # Create a payment payment_id = PaymentApiObject.create( amount=AmountObject("5.00", "EUR"), counterparty_alias=PointerObject("EMAIL", "recipient@example.com"), description="Test payment" ).value print(f"Payment created with ID: {payment_id}") ``` -------------------------------- ### Get Installation Server Public Key (OpenAPI) Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation This OpenAPI specification defines the GET endpoint for retrieving the ServerPublicKey associated with a bunq API installation. It includes details on request parameters, response formats, and error codes. ```json { "openapi": "3.0.0", "info": { "title": "bunq API", "version": "1.0" }, "tags": [ { "name": "server-public-key", "description": "" } ], "servers": [ { "url": "https://public-api.sandbox.bunq.com/{basePath}", "description": "Sandbox server", "variables": { "basePath": { "default": "v1" } } }, { "url": "https://api.bunq.com/{basePath}", "description": "Production server", "variables": { "basePath": { "default": "v1" } } } ], "paths": { "/installation/{installationID}/server-public-key": { "get": { "tags": [ "server-public-key" ], "summary": "", "operationId": "List_all_ServerPublicKey_for_Installation", "description": "Show the ServerPublicKey for this Installation.", "parameters": [ { "in": "path", "name": "installationID", "description": "", "required": true, "schema": { "type": "integer" } }, { "$ref": "#/components/parameters/Cache-Control" }, { "$ref": "#/components/parameters/User-Agent" }, { "$ref": "#/components/parameters/X-Bunq-Language" }, { "$ref": "#/components/parameters/X-Bunq-Region" }, { "$ref": "#/components/parameters/X-Bunq-Client-Request-Id" }, { "$ref": "#/components/parameters/X-Bunq-Geolocation" }, { "$ref": "#/components/parameters/X-Bunq-Client-Authentication" } ], "responses": { "200": { "description": "Using /installation/_/server-public-key you can request the ServerPublicKey again. This is done by referring to the id of the Installation.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/InstallationServerPublicKeyListing" } } } }, "headers": { "X-Bunq-Client-Response-Id": { "$ref": "#/components/headers/X-Bunq-Client-Response-Id" }, "X-Bunq-Client-Request-Id": { "$ref": "#/components/headers/X-Bunq-Client-Request-Id" }, "X-Bunq-Server-Signature": { "$ref": "#/components/headers/X-Bunq-Server-Signature" } } }, "400": { "$ref": "#/components/responses/GenericError" } } } } }, "components": { "parameters": { "Cache-Control": { "description": "The standard HTTP Cache-Control header is required for all signed requests.", "schema": { "type": "string" }, "required": false, "in": "header", "name": "Cache-Control" }, "User-Agent": { "description": "The User-Agent header field should contain information about the user agent originating the request. There are no restrictions on the value of this header.", "schema": { "type": "string" }, "required": true, "in": "header", "name": "User-Agent" }, "X-Bunq-Language": { "description": "The X-Bunq-Language header must contain a preferred language indication. The value of this header is formatted as a ISO 639-1 language code plus a ISO 3166-1 alpha-2 country code, separated by an underscore. Currently only the languages en_US and nl_NL are supported. Anything else will default to en_US.", "schema": { "type": "string" }, "required": false, "in": "header", "name": "X-Bunq-Language" }, "X-Bunq-Region": { "description": "The X-Bunq-Region header must contain the region (country) of the client device. The value of this header is formatted as a ISO 639-1 language code plus a ISO 3166-1 alpha-2 country code, separated by an underscore.", "schema": { "type": "string" }, "required": false, "in": "header", "name": "X-Bunq-Region" }, "X-Bunq-Client-Request-Id": { "description": "This header must specify an ID with each request that is unique for the logged in user. There are no restrictions for the format of this ID. However, the server will respond with an error when the same ID is used again on the same DeviceServer.", "schema": { "type": "string" }, "required": false, "in": "header", "name": "X-Bunq-Client-Request-Id" }, "X-Bunq-Geolocation": { "description": "This header must specify the geolocation of the device. The format of this value is longitude latitude altitude radius country. The country is expected to be formatted of an ISO 3166-1 alpha-2 country code. When no geolocation is available or known the header must still be included but can be zero valued.", "schema": { "type": "string" }, "required": false, "in": "header", "name": "X-Bunq-Geolocation" }, "X-Bunq-Client-Authentication": { "description": "The authentication token is used to authenticate the source of the API call. It is required by all API calls except for POST /v1/installation. It is important to note that the device and session calls are using the token from the response of the installation call, while all the other calls use the token from the response of the session-server call", "schema": { "type": "string" }, "required": true, "in": "header", "name": "X-Bunq-Client-Authentication" } }, "schemas": { "InstallationServerPublicKeyListing": { "type": "object", "properties": { "server_public_key": { "type": "string", "description": "The server's public key for this Installation.", "readOnly": true, "writeOnly": false } } }, "Error": { "type": "array", "items": { "type": "object", "properties": { "error_description": { "type": "string", "description": "The error description in English." }, "error_description_translated": { "type": "string", "description": "The error description translated to the user's language." } } } } }, "headers": { "X-Bunq-Client-Response-Id": { "description": "A unique ID for the response formatted as a UUID. Clients ca" } } } } ``` -------------------------------- ### Installation API Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context Initiates the API context creation process by generating an installation token and the server's public key. ```APIDOC ## POST /installation ### Description This endpoint is used to initiate the API context creation. It's the first step in the bunq authentication process and can be called without any authorization token. ### Method POST ### Endpoint /installation ### Parameters #### Header Parameters - None #### Request Body - **public_key** (string) - Required - The public key of your server. ### Request Example ```json { "public_key": "your_server_public_key" } ``` ### Response #### Success Response (200) - **installation_token** (string) - The token generated for the installation. - **server_public_key** (string) - The public key of the bunq server. ``` -------------------------------- ### Install bunq Python SDK Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/python/usage Installs or upgrades the bunq Python SDK using pip. This is the first step to using the SDK in your Python projects. ```bash pip install bunq_sdk --upgrade ``` -------------------------------- ### POST /installation Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation Installs your public key to create a secure API context for future interactions. ```APIDOC ## POST /installation ### Description This endpoint is used to install your public key, which establishes a secure API context for all subsequent API calls. It ensures that your API key is properly registered and associated with a trusted user, thereby minimizing the risk of unauthorized access. ### Method POST ### Endpoint /installation ### Parameters #### Request Body - **client_public_key** (string) - Required - The public key generated using OpenSSL. ### Request Example ```json { "client_public_key": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA...\n-----END PUBLIC KEY-----" } ``` ### Response #### Success Response (200) - **server_public_key** (string) - The public key of the server, used for further encryption. #### Response Example ```json { "server_public_key": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA...\n-----END PUBLIC KEY-----" } ``` ``` -------------------------------- ### Python: Create Bunq Installation Source: https://doc.bunq.com/basics/signing/python-code-example This function creates a new installation with the Bunq API. It requires the public key in PEM format and returns a device token and server public key. The device token is saved for future use. Dependencies include the 'requests' and 'json' libraries. ```python """ This is a continuation of the bunq_lib.py file we were writting """ def create_installation(self): if self.device_token is not None: print("bunq - Device token already created.") return url = f"{self.base_url}/installation" payload = json.dumps({"client_public_key": self.public_key_pem}) headers = { 'Content-Type': 'application/json', 'User-Agent': self.service_name, 'X-Bunq-Language': 'en_US', 'X-Bunq-Region': 'nl_NL', 'X-Bunq-Geolocation': '0 0 0 0 000', } response = requests.post(url, headers=headers, data=payload) data = response.json() self.device_token = next(item["Token"]["token"] for item in data["Response"] if "Token" in item) self.server_public_key = next(item["ServerPublicKey"]["server_public_key"] for item in data["Response"] if "ServerPublicKey" in item) self.save_device_token() # Save the token for future use ``` -------------------------------- ### Session Token and API Call Example Source: https://doc.bunq.com/basics/authentication/oauth Demonstrates how to request a session to obtain a token and then use that token to make an authenticated GET request to list monetary accounts. ```APIDOC ## Session Token and API Call Example ### Description This section illustrates the process of obtaining a session token and utilizing it for subsequent API requests. After requesting a session, you receive a token along with references to the application and the end user. This session token is crucial for making authenticated API calls. ### Request Example (Session Token) ```json { "Response": [ { "Id": { "id": 26271775 } }, { "Token": { "id": 26271775, "created": "2025-06-25 09:03:11.377820", "updated": "2025-06-25 09:03:11.377820", "token": "0fedc50610b2dcc61997bd817c9b824263ff6fe315234e2a2f0c7e357a3f22a9" } }, { "UserApiKey": { "id": 1964683, "created": "2025-06-25 09:03:00.448648", "updated": "2025-06-25 09:03:00.448648", "requested_by_user": { "UserPaymentServiceProvider": { "id": 1963873, "display_name": "Test PISP AISP 42CF4DAF-898A-44C7-B32C-233CD19D107F", "public_nick_name": "Test PISP AISP 42CF4DAF-898A-44C7-B32C-233CD19D107F", "avatar": { "uuid": "c8559c4f-2d8a-4250-9a78-3f6c66bb69eb", "image": [ { "attachment_public_uuid": "647ba6c1-816e-47e7-93e5-7e2e87a64290", "height": 1023, "width": 1024, "content_type": "image/png", "urls": [ { "type": "ORIGINAL", "url": "https://bunq-triage-model-storage-public.s3.eu-central-1.amazonaws.com/bunq_file/File/content/a3fa4840d155cc0f474258d10eb307f5c673eecf7f6d596a56e71c625cbd8cee.png" } ] } ], "anchor_uuid": "a9805ad4-5f59-4045-8254-2218547e886d", "style": "NONE" }, "session_timeout": 324000 } }, "granted_by_user": { "UserPerson": { "id": 1864430, "display_name": "Jodi", "public_nick_name": "Jodi", "avatar": { "uuid": "298692b3-609a-4012-b77c-814017cb74f2", "image": [ { "attachment_public_uuid": "44420a50-7533-4ba2-8f9f-3cf64c807df2", "height": 1024, "width": 1024, "content_type": "image/jpeg", "urls": [ { "type": "ORIGINAL", "url": "https://bunq-triage-model-storage-public.s3.eu-central-1.amazonaws.com/bunq_file/File/content/21aaad686c9d07ddbddaa624c1762f21c6b9fe6f0637f80fb5804e691bf43325.jpg" } ] } ], "anchor_uuid": "9b26672b-420a-4067-b2b6-0f6ed19a5932", "style": "NONE" }, "session_timeout": 604800 } } } } ] } ``` ### Method GET ### Endpoint `/v1/user/{user_apikey_id}/monetary-account-bank` ### Parameters #### Path Parameters - **user_apikey_id** (integer) - Required - The ID of the user's API key. #### Headers - **User-Agent** (string) - Required - Specifies the client making the request. - **X-Bunq-Client-Authentication** (string) - Required - The session token obtained after requesting a session. - **Content-Type** (string) - Required - Should be `application/json`. ### Request Example ```bash curl -X GET "https://public-api.sandbox.bunq.com/v1/user/{user_apikey_id}/monetary-account-bank" \ -H "User-Agent: text" \ -H "X-Bunq-Client-Authentication: {session_token}" \ -H "Content-Type: application/json" ``` ### Response #### Success Response (200) - **Response** (array) - Contains a list of monetary accounts for the user. - **Id** (object) - Object containing the ID. - **id** (integer) - The unique identifier for the item. - **Token** (object) - Object containing token information. - **id** (integer) - The token ID. - **created** (string) - Timestamp of token creation. - **updated** (string) - Timestamp of token last update. - **token** (string) - The actual session token. - **UserApiKey** (object) - Object containing user API key details. - **id** (integer) - The user API key ID. - **created** (string) - Timestamp of API key creation. - **updated** (string) - Timestamp of API key last update. - **requested_by_user** (object) - Details of the user who requested the API key. - **UserPaymentServiceProvider** (object) - Information about the payment service provider. - **id** (integer) - The ID of the payment service provider. - **display_name** (string) - Display name of the PISP. - **public_nick_name** (string) - Public nickname of the PISP. - **avatar** (object) - Avatar information for the PISP. - **uuid** (string) - UUID of the avatar. - **image** (array) - Array of image objects. - **attachment_public_uuid** (string) - Public UUID of the attached image. - **height** (integer) - Height of the image. - **width** (integer) - Width of the image. - **content_type** (string) - MIME type of the image. - **urls** (array) - Array of URLs for the image. - **type** (string) - Type of URL (e.g., ORIGINAL). - **url** (string) - The image URL. - **anchor_uuid** (string) - UUID of the avatar anchor. - **style** (string) - Style of the avatar. - **session_timeout** (integer) - Session timeout duration for the PISP. - **granted_by_user** (object) - Details of the user who granted the API key. - **UserPerson** (object) - Information about the user. - **id** (integer) - The user ID. - **display_name** (string) - Display name of the user. - **public_nick_name** (string) - Public nickname of the user. - **avatar** (object) - Avatar information for the user. - **uuid** (string) - UUID of the avatar. - **image** (array) - Array of image objects. - **attachment_public_uuid** (string) - Public UUID of the attached image. - **height** (integer) - Height of the image. - **width** (integer) - Width of the image. - **content_type** (string) - MIME type of the image. - **urls** (array) - Array of URLs for the image. - **type** (string) - Type of URL (e.g., ORIGINAL). - **url** (string) - The image URL. - **anchor_uuid** (string) - UUID of the avatar anchor. - **style** (string) - Style of the avatar. - **session_timeout** (integer) - Session timeout duration for the user. #### Response Example ```json { "Response": [ { "Id": { "id": 26271775 } }, { "Token": { "id": 26271775, "created": "2025-06-25 09:03:11.377820", "updated": "2025-06-25 09:03:11.377820", "token": "0fedc50610b2dcc61997bd817c9b824263ff6fe315234e2a2f0c7e357a3f22a9" } }, { "UserApiKey": { "id": 1964683, "created": "2025-06-25 09:03:00.448648", "updated": "2025-06-25 09:03:00.448648", "requested_by_user": { "UserPaymentServiceProvider": { "id": 1963873, "display_name": "Test PISP AISP 42CF4DAF-898A-44C7-B32C-233CD19D107F", "public_nick_name": "Test PISP AISP 42CF4DAF-898A-44C7-B32C-233CD19D107F", "avatar": { "uuid": "c8559c4f-2d8a-4250-9a78-3f6c66bb69eb", "image": [ { "attachment_public_uuid": "647ba6c1-816e-47e7-93e5-7e2e87a64290", "height": 1023, "width": 1024, "content_type": "image/png", "urls": [ { "type": "ORIGINAL", "url": "https://bunq-triage-model-storage-public.s3.eu-central-1.amazonaws.com/bunq_file/File/content/a3fa4840d155cc0f474258d10eb307f5c673eecf7f6d596a56e71c625cbd8cee.png" } ] } ], "anchor_uuid": "a9805ad4-5f59-4045-8254-2218547e886d", "style": "NONE" }, "session_timeout": 324000 } }, "granted_by_user": { "UserPerson": { "id": 1864430, "display_name": "Jodi", "public_nick_name": "Jodi", "avatar": { "uuid": "298692b3-609a-4012-b77c-814017cb74f2", "image": [ { "attachment_public_uuid": "44420a50-7533-4ba2-8f9f-3cf64c807df2", "height": 1024, "width": 1024, "content_type": "image/jpeg", "urls": [ { "type": "ORIGINAL", "url": "https://bunq-triage-model-storage-public.s3.eu-central-1.amazonaws.com/bunq_file/File/content/21aaad686c9d07ddbddaa624c1762f21c6b9fe6f0637f80fb5804e691bf43325.jpg" } ] } ], "anchor_uuid": "9b26672b-420a-4067-b2b6-0f6ed19a5932", "style": "NONE" }, "session_timeout": 604800 } } } } ] } ``` ``` -------------------------------- ### GET /installation/{itemId} Source: https://doc.bunq.com/installation Retrieves a specific installation by its item ID. This is useful for accessing details of a particular installation. ```APIDOC ## GET /installation/{itemId} ### Description Retrieves a specific installation by its item ID. This is useful for accessing details of a particular installation. ### Method GET ### Endpoint /installation/{itemId} ### Parameters #### Path Parameters - **itemId** (string) - Required - The unique identifier for the installation to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) (Refer to the provided OpenAPI specification for success response details) #### Response Example (Refer to the provided OpenAPI specification for response example details) ``` -------------------------------- ### Device Registration and Authentication Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation This section details how to use the installation token and server public key to authenticate and register a device for future API calls. ```APIDOC ## Device Registration and Authentication ### Description Use the `installation_token` and `server_public_key` to authenticate your requests and register your device with the bunq API. ### Method POST ### Endpoint /installation ### Parameters #### Headers - **X-Bunq-Client-Request-Id** (string) - Required - A unique identifier for the request from the logged-in user. #### Request Body - **installation_token** (string) - Required - The token obtained during the installation process. - **server_public_key** (string) - Required - The public key of the server for authentication. ### Request Example ```json { "installation_token": "your_installation_token_here", "server_public_key": "your_server_public_key_here" } ``` ### Response #### Success Response (200) - **token** (string) - The authentication token for subsequent requests. - **device_server_id** (integer) - The ID of the registered device server. #### Response Example ```json { "token": "your_api_token_here", "device_server_id": 12345 } ``` ### Error Handling - **GenericError** (object) - Details about the error response for 4XX codes. - **Error** (object) - The error object containing error details. - **Error_code** (integer) - The error code. - **Error_description** (string) - A description of the error. - **Error_field_location** (string) - The field where the error occurred. - **Error_message** (string) - A more detailed error message. - **Error_status** (integer) - The HTTP status code of the error. ``` -------------------------------- ### Create Installation with bunq API using curl Source: https://doc.bunq.com/psd2/are-you-a-third-party-provider-tpp-start-here/register-as-a-tpp Registers your public installation key with bunq by making a POST request to the /installation endpoint. This command returns an installation token. Requires curl and awk, and the public key generated in the 'Generate Installation Key Pair' step. ```bash INSTALLATION=$(curl -X POST https://public-api.sandbox.bunq.com/v1/installation \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "X-Bunq-Client-Request-Id: $(uuidgen)" \ --data "{\"client_public_key\": \"$(awk 'NF {sub(/\r/, ""); printf "%s\n", $0;}' installation.pub)\"}") ``` -------------------------------- ### GET /get_cards Source: https://doc.bunq.com/basics/signing/python-code-example This endpoint retrieves all available cards associated with the user. ```APIDOC ## GET /get_cards ### Description Retrieves all available cards for the user. ### Method GET ### Endpoint /get_cards ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **response** (object) - The response object containing card information. #### Response Example ```json { "Response": [ { "Card": { "card_number": "1234", "label": "My Card" } } ] } ``` ``` -------------------------------- ### Install Bunq PHP SDK with Composer Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/php This command installs the bunq PHP SDK using Composer, the dependency manager for PHP. Ensure you have Composer installed and configured before running this command. ```bash $ composer require bunq/sdk_php ``` -------------------------------- ### GET /monetary_account Source: https://doc.bunq.com/basics/signing/python-code-example This endpoint retrieves all monetary accounts associated with the user. ```APIDOC ## GET /monetary_account ### Description Retrieves all monetary accounts for the user. ### Method GET ### Endpoint /monetary_account ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **Response** (array) - An array of monetary account objects. - **Pagination** (object) - Pagination details for the response. #### Response Example ```json { "Response": [ { "MonetaryAccountBank": { "id": 1989601, "created": "2025-02-26 16:14:21.031964", "updated": "2025-02-26 16:14:21.031964", "alias": [ { "type": "PHONE_NUMBER", "value": "+31616459904", "name": "+31616459904" } ], "balance": { "currency": "EUR", "value": "998.30" }, "country": "NL", "currency": "EUR", "display_name": "D. Byrne", "description": "Main" } } ], "Pagination": { "future_url": "/v1/user/1800297/monetary-account?newer_id=1989601", "newer_url": null, "older_url": null } } ``` ``` -------------------------------- ### Initialize bunq API Client and Create Session in Python Source: https://doc.bunq.com/basics/signing/python-code-example This Python code snippet initializes the BunqClient with an API key and sets up the necessary components for making API calls, including creating an installation, device server, and session. It uses the FastAPI framework and requires the 'cryptography' library. The code defines endpoints to retrieve monetary accounts and initiate payments. ```python from fastapi import FastAPI from lib.bunq_lib import BunqClient USER_API_KEY = "sandbox_83f4f88a10706750ec2fdcbc1ce97b582a986f2846d33dcaaa974d95" bunq_client = BunqClient(USER_API_KEY, service_name='signingScript') # Run these 1x to initialize your application bunq_client.create_installation() bunq_client.create_device_server() bunq_client.create_session() app = FastAPI() @app.get("/monetary_account") def get_monetary_account(): response = bunq_client.request(endpoint='monetary-account',method='GET',data={}) return response @app.get("/request") def request(): endpoint = f"monetary-account/" response = bunq_client.request(endpoint=endpoint, method='GET', data=None) return response @app.get("/payment") def payment(): payment = bunq_client.create_payment( amount='0.10', recipient_iban='NL14RABO0169202917', currency='EUR', from_monetary_account_id='1989601', description='test' ) return payment ``` -------------------------------- ### Install bunq Sandbox App APK using ADB Source: https://doc.bunq.com/getting-started/tools/android-emulator This command installs the bunq sandbox app APK onto a running Android virtual device. Ensure the virtual device is fully booted and you have navigated to the Android SDK platform-tools directory in your command line. The APK file should be in your Downloads folder. ```bash ./adb install ~/Downloads/bunq-android-sandboxEmulator-public-api.apk ``` -------------------------------- ### Generate Installation Key Pair using OpenSSL Source: https://doc.bunq.com/psd2/are-you-a-third-party-provider-tpp-start-here/register-as-a-tpp Generates a public and private RSA key pair (installation.key and installation.pub) for app installation registration with bunq. Requires OpenSSL to be installed. ```bash # Public key: installation.pub # Private key: installation.key openssl genrsa -out installation.key && openssl rsa -in installation.key -outform PEM -pubout -out installation.pub ``` -------------------------------- ### Generate Public-Private Key Pair using OpenSSL Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation This command generates an RSA public-private key pair using OpenSSL. The private key is saved as 'installation.key' and the public key as 'installation.pub'. Ensure OpenSSL is installed on your system. ```powershell openssl genrsa -out installation.key && openssl rsa -in installation.key -outform PEM -pubout -out installation.pub ``` -------------------------------- ### Make Payment to Another User (Python) Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/python/usage Initiates a payment to another bunq user. This example demonstrates how to send a specific amount with a description, using the recipient's email address as the identifier. ```python from bunq.sdk.model.generated.endpoint import PaymentApiObject from bunq.sdk.model.generated.object_ import AmountObject, PointerObject # Make a payment to another user payment_id = PaymentApiObject.create( amount=AmountObject("5.00", "EUR"), counterparty_alias=PointerObject("EMAIL", "recipient@example.com"), description="Lunch payment" ).value ``` -------------------------------- ### Install bunq.Sdk NuGet Package Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/c Instructions for installing the bunq.Sdk package using the Package Manager Console or the .NET CLI. This package is required to use the bunq C# SDK in your projects. ```powershell Install-Package Bunq.Sdk ``` ```bash dotnet add package Bunq.Sdk ``` -------------------------------- ### Extract Installation Token for Signature Generation Source: https://doc.bunq.com/psd2/are-you-a-third-party-provider-tpp-start-here/register-as-a-tpp Extracts the installation token from a previous step's output, typically stored in an environment variable. This token is a prerequisite for generating the signature of the public key. ```bash TOKEN=$(echo $INSTALLATION | grep -o '"token":"[A-Za-z0-9]*"' | cut -d '"' -f 4) echo -n $TOKEN > installation.token ``` -------------------------------- ### Copy Public Key to Clipboard Source: https://doc.bunq.com/tutorials/your-first-payment/creating-the-api-context/creating-the-installation This command copies the content of the 'installation.pub' file to your system's clipboard. The specific command might vary depending on your operating system (e.g., 'cat' and 'pbcopy' for macOS). ```bash cat $(pwd)/installation.pub | pbcopy ``` -------------------------------- ### Create and Manage API Context (C#) Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/c/usage Demonstrates how to create, save, restore, and load API contexts for sandbox and production environments. It also highlights the importance of initializing the application once and ensuring the session is active. ```csharp // For sandbox environment var apiContext = ApiContext.Create(ApiEnvironmentType.SANDBOX, apiKey, deviceDescription); // For production var apiContext = ApiContext.Create(ApiEnvironmentType.PRODUCTION, apiKey, deviceDescription); // Load the API context into the global BunqContext BunqContext.LoadApiContext(apiContext); // Save the context for later use apiContext.Save("bunq-context.conf"); // Restore context from file var apiContext = ApiContext.Restore("bunq-context.conf"); // Ensure the session is active apiContext.EnsureSessionActive(); // Load into global context BunqContext.LoadApiContext(apiContext); ``` -------------------------------- ### GET /installation/{installationID}/server-public-key Source: https://doc.bunq.com/installation Retrieves the server public key associated with a specific installation. This is crucial for secure communication. ```APIDOC ## GET /installation/{installationID}/server-public-key ### Description Retrieves the server public key associated with a specific installation. This is crucial for secure communication. ### Method GET ### Endpoint /installation/{installationID}/server-public-key ### Parameters #### Path Parameters - **installationID** (string) - Required - The unique identifier for the installation. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) (Refer to the provided OpenAPI specification for success response details) #### Response Example (Refer to the provided OpenAPI specification for response example details) ``` -------------------------------- ### Initialize BunqClient with API Keys and Token Management Source: https://doc.bunq.com/basics/signing/python-code-example Initializes the `BunqClient` class, setting up essential parameters like API key, service name, and base URL. It automatically generates or loads the RSA key pair and attempts to load an existing device token from 'device_token.json'. If no token is found, it prompts for a new one to be created. ```python import json import requests from signing import generate_rsa_key_pair, sign_data # Assuming verify_response is also in signing.py import uuid class BunqClient: def __init__(self, api_key, service_name, base_url="https://public-api.sandbox.bunq.com/v1"): self.service_name = service_name self.api_key = api_key self.private_key_pem, self.public_key_pem = generate_rsa_key_pair() self.device_token = None self.server_public_key = None self.device_server_id = None self.session_token = None self.user_id = None self.base_url = base_url # Try to load device token from file self.load_device_token() def save_device_token(self): """Save the device token to a file.""" with open('device_token.json', 'w') as file: json.dump({"device_token": self.device_token}, file) def load_device_token(self): """Load the device token from a file if it exists.""" try: with open('device_token.json', 'r') as file: data = json.load(file) self.device_token = data.get("device_token") print(f"bunq - Loaded device token from file [KEEP THIS SAFE!]") except FileNotFoundError: print("bunq - No device token found, need to create a new one.") ``` -------------------------------- ### Get Monetary Account Object (Python) Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/python/usage Retrieves a specific monetary account by its ID. This allows you to fetch details of a particular bank account associated with the user. ```python from bunq.sdk.model.generated.endpoint import MonetaryAccountBankApiObject # Get a monetary account monetary_account = MonetaryAccountBankApiObject.get(account_id).value ``` -------------------------------- ### Make and List Payments (C#) Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/c/usage Shows how to initiate payments to other Bunq users or monetary accounts, including specifying amount, currency, and recipient. It also demonstrates listing payments with and without pagination. ```csharp // Create payment to another Bunq user PaymentApiObject.Create( new AmountObject("10.00", "EUR"), // Amount and currency new PointerObject("EMAIL", "user@example.com"), // Recipient "Payment description" // Description ); // Make payment to another monetary account PaymentApiObject.Create( new AmountObject("5.00", "EUR"), recipientAccount.Alias.First(), // The alias of the recipient account "Transfer between accounts" ); // Get all payments var payments = PaymentApiObject.List().Value; // List with pagination var pagination = new Pagination { Count = 10 }; var paymentsPage = PaymentApiObject.List(urlParams: pagination.UrlParamsCountOnly).Value; ``` -------------------------------- ### Pagination: Get Previous and Next Pages Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/python/usage This snippet demonstrates how to check for and retrieve previous and next pages of data using pagination information. It relies on the `pagination_info` object and the `PaymentApiObject.list` method. ```python if pagination_info.has_previous_page(): previous_page = PaymentApiObject.list( params=pagination_info.url_params_previous_page ).value if pagination_info.has_next_page_assured(): next_page = PaymentApiObject.list( params=pagination_info.url_params_next_page ).value ``` -------------------------------- ### Monetary Account Operations (C#) Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/c/usage Provides C# code examples for creating, retrieving, and closing monetary accounts. It covers specifying currency, description, and status updates for account closure. ```csharp // Create a new monetary account with EUR currency var newAccountId = MonetaryAccountBankApiObject.Create("EUR", "My Account Description").Value; // Get account by ID var account = MonetaryAccountBankApiObject.Get(accountId).Value; // Get primary account Account = BunqContext.UserContext.PrimaryMonetaryAccountBank; MonetaryAccountBankApiObject.Update( accountId, status: "CANCELLED", subStatus: "REDEMPTION_VOLUNTARY", reason: "OTHER", reasonDescription: "No longer needed" ); ``` -------------------------------- ### Create and Load API Context (Java) Source: https://doc.bunq.com/getting-started/tools/software-development-kits-sdks/java/usage Establishes an API context by registering an API key and device, then saves and loads it for subsequent API calls. This is a critical first step for any API interaction. Note: This is a heavy task and should ideally be performed once per device. ```java ApiContext apiContext = ApiContext.create( ApiEnvironmentType.SANDBOX, sandboxUser.getApiKey(), "Your Device Description" ); apiContext.save("bunq-config.conf"); BunqContext.loadApiContext(apiContext); /*load the API context to use in your app*/ ``` -------------------------------- ### Example Response Body for Money Request Source: https://doc.bunq.com/tutorials/your-first-payment/setting-up-a-sandbox-user/getting-sandbox-money-on-the-user-account Upon a successful money request, the Bunq API returns a response containing an ID for the initiated request. The absence of an error indicates that Sugar Daddy has received the request. ```json { "Response": [ { "Id": { "id": 1475092 } } ] } ```