Exploring the bunq API using JavaScript

If you're a developer looking to integrate the bunq API into your application, you're in luck! The bunq API is available as a public API, meaning you can access it and use it within your own code. In this article, we'll go over the basics of using the bunq API with JavaScript.

Getting started

Before we start, you'll need an API key from bunq. You can get one by creating a sandbox account. Once you have your API key, you can start making requests to the bunq API.

To get started, let's make a simple GET request to the Accounts endpoint using JavaScript and the fetch function:

const apiKey = 'your-api-key';
const url = `https://public-api.sandbox.bunq.com/v1/user/${apiKey}/monetary-account`;

fetch(url, {
  headers: {'X-Bunq-Client-Authentication': apiKey},
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));

This code will make a request to the monetary-account endpoint and return the data in JSON format. Make sure to replace your-api-key with your actual API key.

Creating a payment

Now let's create a payment using the POST /v1/user/{user_id}/monetary-account/{monetary_account_id}/payment endpoint. Here's how you can do it in JavaScript:

const apiKey = 'your-api-key';
const url = `https://public-api.sandbox.bunq.com/v1/user/${apiKey}/monetary-account/your-monetary-account-id/payment`;

const data = {
  amount: {
    value: '0.01',
    currency: 'EUR',
  },
  counterparty_alias: {
    type: 'EMAIL',
    value: 'example@bunq.com',
    name: 'Bunq Example',
  },
  description: 'Test payment',
};

fetch(url, {
  method: 'POST',
  headers: {
    'X-Bunq-Client-Authentication': apiKey,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));

This code will create a payment of 0.01 EURO to the email address example@bunq.com. Don't forget to replace your-monetary-account-id with the ID of your monetary account.

Conclusion

In this article, we covered the basics of using the bunq API with JavaScript. We made a simple GET request to the Accounts endpoint and created a payment using the POST /v1/user/{user_id}/monetary-account/{monetary_account_id}/payment endpoint. With this knowledge, you can start exploring the bunq API and integrating it into your own applications. For more information, check out the official bunq API documentation.

Related APIs in Finance