Developer-friendly & type-safe Typescript SDK specifically catered to leverage *mollie-api-typescript* API.
npm install mollie-api-typescriptDeveloper-friendly & type-safe Typescript SDK specifically catered to leverage mollie-api-typescript API.
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
``bash`
npm add mollie-api-typescript
`bash`
pnpm add mollie-api-typescript
`bash`
bun add mollie-api-typescript
`bash`
yarn add mollie-api-typescript
> [!NOTE]
> This package is published with CommonJS and ES Modules (ESM) support.
This SDK is also an installable MCP server where the various SDK methods are
exposed as tools that can be invoked by AI applications.
> Node.js v20 or greater is required to run the MCP server from npm.
Claude installation steps
Add the following server definition to your claude_desktop_config.json file:
`json`
{
"mcpServers": {
"Client": {
"command": "npx",
"args": [
"-y", "--package", "mollie-api-typescript",
"--",
"mcp", "start",
"--api-key", "...",
"--o-auth", "...",
"--profile-id", "...",
"--testmode", "...",
"--custom-user-agent", "..."
]
}
}
}
Cursor installation steps
Create a .cursor/mcp.json file in your project root with the following content:
`json`
{
"mcpServers": {
"Client": {
"command": "npx",
"args": [
"-y", "--package", "mollie-api-typescript",
"--",
"mcp", "start",
"--api-key", "...",
"--o-auth", "...",
"--profile-id", "...",
"--testmode", "...",
"--custom-user-agent", "..."
]
}
}
}
You can also run MCP servers as a standalone binary with no additional dependencies. You must pull these binaries from available Github releases:
`bash`
curl -L -o mcp-server \
https://github.com/{org}/{repo}/releases/download/{tag}/mcp-server-bun-darwin-arm64 && \
chmod +x mcp-server
If the repo is a private repo you must add your Github PAT to download a release -H "Authorization: Bearer {GITHUB_PAT}".
`json`
{
"mcpServers": {
"Todos": {
"command": "./DOWNLOAD/PATH/mcp-server",
"args": [
"start"
]
}
}
}
For a full list of server arguments, run:
`sh`
npx -y --package mollie-api-typescript -- mcp start --help
For supported JavaScript runtimes, please consult RUNTIMES.md.
`typescript
import { Client } from "mollie-api-typescript";
const client = new Client({
testmode: false,
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
});
async function run() {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
console.log(result);
}
run();
`
This SDK supports the following security schemes globally:
| Name | Type | Scheme | Environment Variable |
| -------- | ------ | ------------ | -------------------- |
| apiKey | http | HTTP Bearer | CLIENT_API_KEY |oAuth
| | oauth2 | OAuth2 token | CLIENT_O_AUTH |
You can set the security parameters through the security optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:`typescript
import { Client } from "mollie-api-typescript";
const client = new Client({
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
testmode: false,
});
async function run() {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
console.log(result);
}
run();
`
This SDK supports the usage of Idempotency Keys. See our documentation on how to use it.
`typescript
import { Client } from "mollie-api-typescript";
let client = new Client({
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
}
})
let idempotencyKey = '
let payload = {
description: "Description",
amount: {
currency: "EUR",
value: "5.00",
},
redirectUrl: "https://example.org/redirect",
}
let payment1 = await client.payments.create(
{
paymentRequest: payload,
idempotencyKey: idempotencyKey
}
);
let payment2 = await client.payments.create(
{
paymentRequest: payload,
idempotencyKey: idempotencyKey
}
);
console.log(Payment with id: ${payment1.id});Payment with id: ${payment2.id}
console.log();`
console.log(payment1.id === payment2.id ? "Payments are the same" : "Payments are different");
header for all requests. This can be used to identify
your application or integration when interacting with the API, making it easier to track usage or debug requests. The suffix is automatically added to the default User-Agent string generated by the SDK. You can add it when creating the
client:`js
let client = new Client({
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
customUserAgent: "insert something here"
})
`Add Profile ID and Testmode to Client
The SDK allows you to define the profileId and testmode in the client. This way, you don't need to add this
information to the payload every time when using OAuth. This will not override the details provided in the individual
requests.`ts
let client = new Client({
security: {
oAuth: process.env["CLIENT_OAUTH_KEY"] ?? "",
},
testmode: false,
profileId: "pfl_..."
})
`
Available Resources and Operations
Available methods
$3
* create - Create a Connect balance transfer
* list - List all Connect balance transfers
* get - Get a Connect balance transfer
$3
* list - List balances
* get - Get balance
* getPrimary - Get primary balance
* getReport - Get balance report
* listTransactions - List balance transactions
$3
* list - List capabilities
$3
* create - Create capture
* list - List captures
* get - Get capture
$3
* list - List payment chargebacks
* get - Get payment chargeback
* all - List all chargebacks
$3
* create - Create client link
$3
* list - List clients
* get - Get client
$3
* create - Create customer
* list - List customers
* get - Get customer
* update - Update customer
* delete - Delete customer
* createPayment - Create customer payment
* listPayments - List customer payments
$3
* create - Create a delayed route
* list - List payment routes
* get - Get a delayed route
$3
* list - List invoices
* get - Get invoice
$3
* create - Create mandate
* list - List mandates
* get - Get mandate
* revoke - Revoke mandate
$3
* list - List payment methods
* all - List all payment methods
* get - Get payment method
$3
* get - Get onboarding status
* submit - Submit onboarding data
$3
* get - Get organization
* getCurrent - Get current organization
* getPartner - Get partner status
$3
* create - Create payment link
* list - List payment links
* get - Get payment link
* update - Update payment link
* delete - Delete payment link
* listPayments - Get payment link payments
$3
* create - Create payment
* list - List payments
* get - Get payment
* update - Update payment
* cancel - Cancel payment
* releaseAuthorization - Release payment authorization
$3
* list - List permissions
* get - Get permission
$3
* create - Create profile
* list - List profiles
* get - Get profile
* update - Update profile
* delete - Delete profile
* getCurrent - Get current profile
$3
* create - Create payment refund
* list - List payment refunds
* get - Get payment refund
* cancel - Cancel payment refund
* all - List all refunds
$3
* create - Create sales invoice
* list - List sales invoices
* get - Get sales invoice
* update - Update sales invoice
* delete - Delete sales invoice
$3
* list - List settlements
* get - Get settlement
* getOpen - Get open settlement
* getNext - Get next settlement
* listPayments - List settlement payments
* listCaptures - List settlement captures
* listRefunds - List settlement refunds
* listChargebacks - List settlement chargebacks
$3
* create - Create subscription
* list - List customer subscriptions
* get - Get subscription
* update - Update subscription
* cancel - Cancel subscription
* all - List all subscriptions
* listPayments - List subscription payments
$3
* list - List terminals
* get - Get terminal
$3
* requestApplePaySession - Request Apple Pay payment session
$3
* get - Get a Webhook Event
$3
* create - Create a webhook
* list - List all webhooks
* update - Update a webhook
* get - Get a webhook
* delete - Delete a webhook
* test - Test a webhook
Standalone functions
All the methods listed above are available as standalone functions. These
functions are ideal for use in applications running in the browser, serverless
runtimes or other environments where application bundle size is a primary
concern. When using a bundler to build your application, all unused
functionality will be either excluded from the final bundle or tree-shaken away.
To read more about standalone functions, check FUNCTIONS.md.
Available standalone functions
balancesGet - Get balance
- balancesGetPrimary - Get primary balance
- balancesGetReport - Get balance report
- balancesList - List balances
- balancesListTransactions - List balance transactions
- balanceTransfersCreate - Create a Connect balance transfer
- balanceTransfersGet - Get a Connect balance transfer
- balanceTransfersList - List all Connect balance transfers
- capabilitiesList - List capabilities
- capturesCreate - Create capture
- capturesGet - Get capture
- capturesList - List captures
- chargebacksAll - List all chargebacks
- chargebacksGet - Get payment chargeback
- chargebacksList - List payment chargebacks
- clientLinksCreate - Create client link
- clientsGet - Get client
- clientsList - List clients
- customersCreate - Create customer
- customersCreatePayment - Create customer payment
- customersDelete - Delete customer
- customersGet - Get customer
- customersList - List customers
- customersListPayments - List customer payments
- customersUpdate - Update customer
- delayedRoutingCreate - Create a delayed route
- delayedRoutingGet - Get a delayed route
- delayedRoutingList - List payment routes
- invoicesGet - Get invoice
- invoicesList - List invoices
- mandatesCreate - Create mandate
- mandatesGet - Get mandate
- mandatesList - List mandates
- mandatesRevoke - Revoke mandate
- methodsAll - List all payment methods
- methodsGet - Get payment method
- methodsList - List payment methods
- onboardingGet - Get onboarding status
- onboardingSubmit - Submit onboarding data
- organizationsGet - Get organization
- organizationsGetCurrent - Get current organization
- organizationsGetPartner - Get partner status
- paymentLinksCreate - Create payment link
- paymentLinksDelete - Delete payment link
- paymentLinksGet - Get payment link
- paymentLinksList - List payment links
- paymentLinksListPayments - Get payment link payments
- paymentLinksUpdate - Update payment link
- paymentsCancel - Cancel payment
- paymentsCreate - Create payment
- paymentsGet - Get payment
- paymentsList - List payments
- paymentsReleaseAuthorization - Release payment authorization
- paymentsUpdate - Update payment
- permissionsGet - Get permission
- permissionsList - List permissions
- profilesCreate - Create profile
- profilesDelete - Delete profile
- profilesGet - Get profile
- profilesGetCurrent - Get current profile
- profilesList - List profiles
- profilesUpdate - Update profile
- refundsAll - List all refunds
- refundsCancel - Cancel payment refund
- refundsCreate - Create payment refund
- refundsGet - Get payment refund
- refundsList - List payment refunds
- salesInvoicesCreate - Create sales invoice
- salesInvoicesDelete - Delete sales invoice
- salesInvoicesGet - Get sales invoice
- salesInvoicesList - List sales invoices
- salesInvoicesUpdate - Update sales invoice
- settlementsGet - Get settlement
- settlementsGetNext - Get next settlement
- settlementsGetOpen - Get open settlement
- settlementsList - List settlements
- settlementsListCaptures - List settlement captures
- settlementsListChargebacks - List settlement chargebacks
- settlementsListPayments - List settlement payments
- settlementsListRefunds - List settlement refunds
- subscriptionsAll - List all subscriptions
- subscriptionsCancel - Cancel subscription
- subscriptionsCreate - Create subscription
- subscriptionsGet - Get subscription
- subscriptionsList - List customer subscriptions
- subscriptionsListPayments - List subscription payments
- subscriptionsUpdate - Update subscription
- terminalsGet - Get terminal
- terminalsList - List terminals
- walletsRequestApplePaySession - Request Apple Pay payment session
- webhookEventsGet - Get a Webhook Event
- webhooksCreate - Create a webhook
- webhooksDelete - Delete a webhook
- webhooksGet - Get a webhook
- webhooksList - List all webhooks
- webhooksTest - Test a webhook
- webhooksUpdate - Update a webhook
Global Parameters
Certain parameters are configured globally. These parameters may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, These global values will be used as defaults on the operations that use them. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set
profileId to at SDK initialization and then you do not have to pass the same value on calls to operations like list. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
$3
The following global parameters are available.
Global parameters can also be set via environment variable.
| Name | Type | Description | Environment |
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------ |
| profileId | string | The identifier referring to the profile you wish to
retrieve the resources for.
Most API credentials are linked to a single profile. In these cases the
profileId can be omitted. For
organization-level credentials such as OAuth access tokens however, the profileId parameter is required. | CLIENT_PROFILE_ID |
| testmode | boolean | Most API credentials are specifically created for either live mode or test mode. In those cases the testmode query
parameter can be omitted. For organization-level credentials such as OAuth access tokens, you can enable test mode by
setting the testmode query parameter to true.
Test entities cannot be retrieved when the endpoint is set to live mode, and vice versa. | CLIENT_TESTMODE |
| customUserAgent | string | Custom user agent string to be appended to the default Mollie SDK user agent. | CLIENT_CUSTOM_USER_AGENT |$3
`typescript
import { Client } from "mollie-api-typescript";const client = new Client({
testmode: false,
profileId: "",
customUserAgent: "",
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
});
async function run() {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
console.log(result);
}
run();
`
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
`typescript
import { Client } from "mollie-api-typescript";const client = new Client({
testmode: false,
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
});
async function run() {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
}, {
retries: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
});
console.log(result);
}
run();
`If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
`typescript
import { Client } from "mollie-api-typescript";const client = new Client({
retryConfig: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
testmode: false,
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
});
async function run() {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
console.log(result);
}
run();
`
Error Handling
ClientError is the base class for all HTTP error responses. It has the following properties:| Property | Type | Description |
| ------------------- | ---------- | --------------------------------------------------------------------------------------- |
|
error.message | string | Error message |
| error.statusCode | number | HTTP response status code eg 404 |
| error.headers | Headers | HTTP response headers |
| error.body | string | HTTP body. Can be empty string if no body is returned. |
| error.rawResponse | Response | Raw HTTP response |
| error.data$ | | Optional. Some errors may contain structured data. See Error Classes. |$3
`typescript
import { Client } from "mollie-api-typescript";
import * as errors from "mollie-api-typescript/models/errors";const client = new Client({
testmode: false,
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
});
async function run() {
try {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
console.log(result);
} catch (error) {
// The base class for HTTP error responses
if (error instanceof errors.ClientError) {
console.log(error.message);
console.log(error.statusCode);
console.log(error.body);
console.log(error.headers);
// Depending on the method different errors may be thrown
if (error instanceof errors.ErrorResponse) {
console.log(error.data$.status); // number
console.log(error.data$.title); // string
console.log(error.data$.detail); // string
console.log(error.data$.field); // string
console.log(error.data$.links); // models.ErrorResponseLinks
}
}
}
}
run();
`$3
Primary errors:
* ClientError: The base class for HTTP error responses.
ErrorResponse: An error response object. Less common errors (6)
ConnectionError: HTTP client was unable to make a request to a server.
* RequestTimeoutError: HTTP request timed out due to an AbortSignal signal.
* RequestAbortedError: HTTP request was aborted by the client.
* InvalidRequestError: Any input used to create a request is invalid.
* UnexpectedClientError: Unrecognised or unexpected error.ClientError:
* ResponseValidationError: Type mismatch between the data returned from the server and the structure expected by the SDK. See error.rawValue for the raw value and error.pretty() for a nicely formatted multi-line string.\* Check the method documentation to see if the error is applicable.
Server Selection
$3
The default server can be overridden globally by passing a URL to the
serverURL: string optional parameter when initializing the SDK client instance. For example:
`typescript
import { Client } from "mollie-api-typescript";const client = new Client({
serverURL: "https://api.mollie.com/v2",
testmode: false,
security: {
apiKey: process.env["CLIENT_API_KEY"] ?? "",
},
});
async function run() {
const result = await client.balances.list({
currency: "EUR",
from: "bal_gVMhHKqSSRYJyPsuoPNFH",
limit: 50,
idempotencyKey: "123e4567-e89b-12d3-a456-426",
});
console.log(result);
}
run();
`
Custom HTTP Client
The TypeScript SDK makes API calls using an
HTTPClient that wraps the native
Fetch API. This
client is a thin wrapper around fetch and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.The
HTTPClient constructor takes an optional fetcher argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.The following example shows how to use the
"beforeRequest" hook to to add a
custom header and a timeout to requests and how to use the "requestError" hook
to log errors:`typescript
import { Client } from "mollie-api-typescript";
import { HTTPClient } from "mollie-api-typescript/lib/http";const httpClient = new HTTPClient({
// fetcher takes a function that has the same signature as native
fetch.
fetcher: (request) => {
return fetch(request);
}
});httpClient.addHook("beforeRequest", (request) => {
const nextRequest = new Request(request, {
signal: request.signal || AbortSignal.timeout(5000)
});
nextRequest.headers.set("x-custom-header", "custom value");
return nextRequest;
});
httpClient.addHook("requestError", (error, request) => {
console.group("Request Error");
console.log("Reason:",
${error});
console.log("Endpoint:", ${request.method} ${request.url});
console.groupEnd();
});const sdk = new Client({ httpClient: httpClient });
`
Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches
console's interface as an SDK option.> [!WARNING]
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
`typescript
import { Client } from "mollie-api-typescript";const sdk = new Client({ debugLogger: console });
`You can also enable a default debug logger by setting an environment variable
CLIENT_DEBUG` to true.While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.