@formbricks/api

中文文档
3.0.0发布于 2024/12/19MITTypeScriptESM + CJS零依赖近 30 天下载 3万

Formbricks-api is an api wrapper for the Formbricks client API

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Init
  4. Display
  5. Response
  6. Contact Attributes
  7. Storage

@formbricks/api - API Wrapper for Formbricks

This is the official API wrapper for Formbricks. It is used to interact with the Formbricks API. To know more about Formbricks, visit Formbricks.com.

The direct API documentation can be found in our official docs here. To interact with the Formbricks API, you need to have an environment ID. You can get it from the Formbricks dashboard at app.formbricks.com.

Installation

npm install @formbricks/api

Usage

Init

import { FormbricksAPI } from "@formbricks/api";

const api = new FormbricksAPI({
  apiHost: `https://app.formbricks.com`, // If you have self-hosted Formbricks, change this to your self hosted instance's URL
  environmentId: "<environment-id>", // Replace this with your Formbricks environment ID
});

The API client is now ready to be used across your project. It can be used to interact with the following models:

Display

  • Create a Display

    await api.client.display.create({
      surveyId: "<your-survey-id>", // required
      userId: "<your-user-id>", // optional
      responseId: "<your-response-id>", // optional
    });
    

Response

  • Create a Response

    await api.client.response.create({
      surveyId: "<your-survey-id>", // required
      finished: boolean, // required
      data: {
        questionId: "<answer-to-this-question-in-string>",
        anotherQuestionId: 123, // answer to this question in number
        yetAnotherQuestionId: ["option1", "option2"], // answer to this question in array,
      }, // required
    
      userId: "<your-user-id>", // optional
      singleUseId: "<your-single-use-id>", // optional
      ttc: {
        questionId: 123, // optional
      }, // optional
      meta: {
        source: "<your-source>", // optional
        url: "<your-url>", // optional
        userAgent: {
          browser: "<your-browser>", // optional
          device: "<your-device>", // optional
          os: "<your-os>", // optional
        },
        country: "<your-country>", // optional
      }, // optional
    });
    
  • Update a Response

    await api.client.response.update({
      responseId: "<your-response-id>", // required
      finished: boolean, // required
      data: {
        questionId: "<answer-to-this-question-in-string>",
        anotherQuestionId: 123, // answer to this question in number
        yetAnotherQuestionId: ["option1", "option2"], // answer to this question in array,
      }, // required
      ttc: {
        questionId: 123, // optional
      }, // optional
    });
    

Contact Attributes

  • Update contact attributes

    await api.client.attribute.update({
      userId: "<your-user-id>", // required
      attributes: {
        plan: "Pro",
      }, // required
    });
    

Storage

  • Upload a file

    await api.client.storage.uploadFile(
      file: File, // required (of interface File of the browser's File API)
      {
        allowedFileTypes: ["file-type-allowed", "for-example", "image/jpeg"], // optional
        surveyId: "<your-survey-id>", // optional
    
      } // optional
    );
    

If you have any questions or need help, feel free to reach out to us on Github Discussions

版本与发布记录

@formbricks/api 共发布 9 个版本,首次发布于 2023/06/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.0latest2024/12/191.9 年前
1.9.02024/09/202 年前
1.7.02024/03/192 年前
1.6.02024/02/272 年前
1.5.02024/01/272 年前
1.4.02023/12/212 年前

关于 @formbricks/api 的常见问题

@formbricks/api 是什么?

Formbricks-api is an api wrapper for the Formbricks client API

如何安装 @formbricks/api?

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

@formbricks/api 支持 TypeScript 吗?

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

@formbricks/api 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@formbricks/api 可以商用吗?

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

@formbricks/api 的下载量有多少?

根据 npm 官方下载统计,@formbricks/api 在 2026/10/16 – 2026/11/14 这 30 天内被下载 30,491 次,日均约 1,016 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@formbricks/api 还在维护吗?

最新版本 3.0.0 发布于 2024/12/19(1.9 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/06/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。