@mittwald/api-client

中文文档
4.509.0发布于 2026/11/02MITTypeScriptES Module构建来源已验证

Auto-generated client for the mittwald API

原始使用文档
文档目录19 节
  1. License
  2. Table of contents
  3. Installing
  4. Usage
  5. Using the v3-next client
  6. Setting request parameters
  7. Example
  8. Usage in React
  9. Installation
  10. Setup
  11. Usage
  12. Example
  13. API documentation
  14. Accessing the underlying Axios instance
  15. Adding custom HTTP headers
  16. Intercepting requests or responses
  17. Usage with TypeScript
  18. Referencing request/response types
  19. Migrating from package version V2 to V3

mittwald API JavaScript client

This package contains a (mostly auto-generated) JavaScript client for the mittwald API.

License

Copyright (c) 2023 Mittwald CM Service GmbH & Co. KG and contributors

This project (and all NPM packages) therein is licensed under the MIT License; see the LICENSE file for details.

Table of contents

Installing

You can install this package from the regular NPM registry:

yarn add @mittwald/api-client

Usage

Import the client:

import { MittwaldAPIV2Client } from "@mittwald/api-client";

To create a client instance you can use one of the following factory method for different types of authentication:

  1. MittwaldAPIClient.newUnauthenticated()
  2. MittwaldAPIClient.newWithToken(apiToken: string) (recommended)
  3. MittwaldAPIClient.newWithCredentials(email: string, password: string) (does actually perform a login in the background and thus returns a promise)

Have a look at our API introduction for more information on how to obtain an API token and how to get started with the API.

Using the v3-next client

The default import path exposes the v2 client. To use the production v3-next client, import it from the @mittwald/api-client/v3-next subpath:

import { MittwaldAPIClient } from "@mittwald/api-client/v3-next";

const mittwaldApi = MittwaldAPIClient.newWithToken("your-access-token");

The React client is available from the matching React subpath:

import { MittwaldAPIClientReact } from "@mittwald/api-client/v3-next/react";

TypeScript request and response types are exported through the MittwaldAPIV3Next namespace:

import { MittwaldAPIV3Next } from "@mittwald/api-client/v3-next";

This uses the published, non-development v3-next client. The package does not expose a @mittwald/api-client/v3-next-dev import path; the v3-next-dev OpenAPI spec is only used for generating development builds.

Setting request parameters

API requests may require these type of parameters:

  • path parameters
  • headers
  • query parameters
  • request body

Path parameters

Path parameters are variable parts of a URL path. They are typically used to point to a specific resource within a collection, such as a project identified by ID. A URL can have several path parameters, each denoted with curly braces { }.

/v2/projects/{projectId}

Path parameters are required and must be directly defined inside the request object.

// Setting the projectId path parameters
const project = await mittwaldApi.project.getProject({
  projectId: "p-xxxxx",
});

Headers, query parameters and request body

Depending on the operation, you must configure additional parameters, such as queryParameters (URL query parameters), headers (HTTP headers), and data (request body).

The operations and their parameters are documented in the API documentation.

When using TypeScript all parameter schemas are reflected by the request type, so you will get compile errors, when a request does not match the schema.

const response = await mittwaldApi.category.operation({
  // path parameters
  pathParameter1: "param1",
  pathParameter2: "param2",
  // parameters in header
  headers: {
    "x-header": "header",
  },
  // query parameters
  queryParameters: {
    queryParameter1: "queryParam1",
    queryParameter2: "queryParam2",
  },
  // JSON object in request body
  data: {
    data1: "data1",
    data2: "data2",
  },
});

Date and time values

Wherever the API expects a date and time (an ISO 8601 string in the API documentation), you can either pass that string yourself or simply pass a JavaScript Date. Date values are converted to ISO 8601 before the request is sent – in the request body (at any nesting depth), in query parameters, path parameters and headers.

await mittwaldApi.contract.terminateContractItem({
  contractId: "contract-id",
  contractItemId: "contract-item-id",
  data: {
    terminationTargetDate: new Date("2024-12-10"),
  },
});

Note that this applies to date-time values only. Date-only values (YYYY-MM-DD) still have to be passed as a string, and responses always contain strings, never Date objects.

Example

import { MittwaldAPIV2Client } from "@mittwald/api-client";

const mittwaldApi = MittwaldAPIClient.newWithToken("your-access-token");

const projects = await mittwaldApi.project.listProjects();

Usage in React

This package also provides a client aligned to be used in React components. It uses @mittwald/react-use-promise to encapsulate the asynchronous API functions into AsyncResources. More details about how to use AsyncResources see the package documentation.

Installation

To use the React client you have to install the additional @mittwald/react-use-promise package:

yarn add @mittwald/react-use-promise

Setup

To create a React client instance, you first need an instance of the regular (promise-based) client. Then you can use the .fromBaseClient(api) method to build the React client.

const api = MittwaldAPIV2Client.newUnauthenticated();
const apiReact = MittwaldAPIV2ClientReact.fromBaseClient(api);

Usage

The React client has an equivalent for every GET method of the regular client. The methods returning an AsyncResource that can be used to get the API responses.

If the response is not OK (status 200), an ApiClientError will be thrown. Errors can be handled by using error-boundaries. See the error handling section for more details.

Example

import { MittwaldAPIV2Client } from "@mittwald/api-client";
import { MittwaldAPIV2ClientReact } from "@mittwald/api-client/react";

const api = MittwaldAPIV2Client.newUnauthenticated();
const apiReact = MittwaldAPIV2ClientReact.fromBaseClient(api);

const ProjectsList = () => {
  // apiReact.project.listProjects() returns an AsyncResource that can be "used"
  const projects = apiReact.project.listProjects().use({
    autoRefresh: {
      seconds: 30,
    },
  });

  return (
    <ul>
      {projects.map((p) => (
        <li key={p.id}>{p.description}</li>
      ))}
    </ul>
  );
};

API documentation

The API documentation can be found at https://api.mittwald.de/v2/docs/. You can find the operation ID on the right side of each operation.

Accessing the underlying Axios instance

The client uses the popular Axios HTTP client under the hood. You may access the Axios instance with the clients axios property.

Adding custom HTTP headers

To add custom HTTP headers to all requests you can use Axios' defaults.headers property:

client.axios.defaults.headers["User-Agent"] = `your-tool/v1.2.3`;

Intercepting requests or responses

To intercept requests or responses you can use Axios' interceptors.

Usage with TypeScript

All response and request types can be imported from the MittwaldAPIV2 namespace.

Referencing request/response types

import { MittwaldAPIV2 } from "@mittwald/api-client";

type ProjectData = MittwaldAPIV2.Operations.ProjectGetProject.ResponseData;

// Reference "non-200" response type
type ProjectNotFoundData =
  MittwaldAPIV2.Operations.ProjectGetProject.ResponseData<404>;

type CreateProjectData =
  MittwaldAPIV2.Operations.ProjectCreateProject.RequestData;

Migrating from package version V2 to V3

This instruction considers migrating from package version V2 to V3, which has a breaking change in the call signature of request calls. The API itself has not changed and is still at version 2.

Path parameters are a primary component of the request and thus should not be "hidden" in the request config object. In V3 the API of the request configuration object has changed, and you have to set the path parameters directly in the root level of the request object.

// V2
mittwaldApi.project.getProject({
  pathParameters: {
    projectId: "p-xxxxx",
  },
});

// V3
mittwaldApi.project.getProject({
  projectId: "p-xxxxx",
});

版本与发布记录

@mittwald/api-client 共发布 803 个版本,首次发布于 2023/06/07;过去 12 个月发布了 375 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.509.0latest2026/11/021 天前
4.508.02026/11/012 天前
4.507.02026/10/313 天前
0.0.0-development-7d1b6db-20261028development2026/10/295 天前
4.506.02026/10/295 天前
0.0.0-development-492ba61-202610272026/10/286 天前

其他发布通道:experimental → 0.0.0-experimental-d7a1e55-20260706,development-experimental → 0.0.0-experimental-dev-8fc4091-20260706,development → 0.0.0-development-7d1b6db-20261028。

关于 @mittwald/api-client 的常见问题

@mittwald/api-client 是什么?

为mittwald API自动生成客户端

如何安装 @mittwald/api-client?

在项目目录运行 npm install @mittwald/api-client,或使用 pnpm add / yarn add / bun add。

@mittwald/api-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@mittwald/api-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@mittwald/api-client 可以商用吗?

@mittwald/api-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@mittwald/api-client 还在维护吗?

最新版本 4.509.0 发布于 2026/11/02(1 天前);至今共发布 803 个版本,其中过去 12 个月发布了 375 个;首次发布于 2023/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。