Mollie API TypeScript SDK
This is the official TypeScript SDK for interacting with the Mollie Payments API, providing a type-safe and developer-friendly interface. It is currently at version 1.5.2 and maintains a rapid release cadence, with updates often published multiple times a week. The SDK is automatically generated using the Speakeasy CLI based on the Mollie OpenAPI specification, ensuring it stays up-to-date with the latest API changes. Key differentiators include full TypeScript support for robust development, explicit handling for authentication via API keys, organization access tokens, or OAuth, and built-in features like idempotency keys, custom User-Agent headers, pagination helpers, and automatic retry mechanisms. It supports both CommonJS and ES Modules runtimes for broad compatibility.
Common errors
-
Error: Unauthorized
cause The API request failed due to missing, invalid, or insufficient authentication credentials (API key, organization access token, or OAuth token).fixVerify that your `security` configuration when initializing the `Client` is correct and that the associated environment variable (e.g., `CLIENT_ORGANIZATION_ACCESS_TOKEN`) holds a valid, active token with the necessary permissions. -
TypeError: client.payments.create is not a function
cause Attempting to call an API method that does not exist on the current `Client` instance, often due to an outdated SDK version or a typo in the method name.fixUpdate the `mollie-api-typescript` package to the latest version using `npm update mollie-api-typescript` or `yarn upgrade mollie-api-typescript`. Double-check the SDK documentation for the correct method names and casing. -
Property 'storeCredentials' does not exist on type 'PaymentRequest'.
cause This TypeScript error indicates that a property (e.g., `storeCredentials`) you are trying to use in a request object is not defined in the SDK's type definitions for that version, likely because it's a new API feature.fixUpdate `mollie-api-typescript` to the latest version. New API features and corresponding request/response properties are added as the SDK is generated from the most recent OpenAPI specification. -
ReferenceError: process is not defined
cause The code is attempting to access `process.env` (a Node.js global) in a browser or other non-Node.js environment where `process` is not available.fixWhen running in a browser environment, configure your build tools (e.g., Webpack, Rollup, Parcel, Vite) to provide a polyfill or substitute for `process.env`, or pass environment variables explicitly during the build process instead of relying on runtime access.
Warnings
- breaking Breaking changes were introduced in v1.3.5 related to the settlements API. The `request.testmode` parameter was removed from `client.settlements.listPayments()`, `listCaptures()`, and `listRefunds()`, and the response structures (`response.Embedded.payments[]`, `captures[]`, `refunds[]`) were also changed.
- gotcha The SDK is automatically generated via Speakeasy CLI, meaning updates to the underlying Mollie OpenAPI specification can lead to new features, changes, or even breaking modifications being introduced in minor version bumps of the SDK. Developers should closely monitor release notes for changes, even when updating patch or minor versions.
- gotcha The SDK supports multiple authentication schemes: `apiKey` (HTTP Bearer for profile-specific access), `organizationAccessToken` (HTTP Bearer for organization-wide access), and `oAuth` (OAuth2 token). Misconfiguring or providing the wrong type of token can lead to authentication failures.
- gotcha The SDK automatically handles pagination for list operations through async iterators (e.g., `for await (const page of result)`). If not used correctly, developers might only retrieve the first page of results or encounter unexpected behavior when iterating.
Install
-
npm install mollie-api-typescript -
yarn add mollie-api-typescript -
pnpm add mollie-api-typescript
Imports
- Client
const { Client } = require('mollie-api-typescript');import { Client } from 'mollie-api-typescript'; - PaymentRequest
import { PaymentRequest } from 'mollie-api-typescript';import { components } from 'mollie-api-typescript'; - Balance
import { Balance } from 'mollie-api-typescript';import { components } from 'mollie-api-typescript';
Quickstart
import { Client } from "mollie-api-typescript";
const client = new Client({
testmode: false,
security: {
organizationAccessToken: process.env["CLIENT_ORGANIZATION_ACCESS_TOKEN"]
?? "",
},
});
async function run() {
try {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
for await (const page of result) {
console.log(page);
}
} catch (error) {
console.error("Error fetching balances:", error);
}
}
run();