@ formbricks/ api - 用于 Formbricks 的 API 包装器
这是Formbricks的官方API包装. 它用于与Formbricks API交互. 要知道更多关于Formbricks,访问 Formbricks.com (英语)。 。 。 .
直接的API文档可见于我们的官方文件 这里。要与Formbricks API互动,您需要环境标识。 你可以从Formbricks的仪表板上得到 app.formbricks.com (中文(简体) )。 。 。 .
安装
npm install @formbricks/api
使用量
输入
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
});
API 客户端现在准备在您的整个项目中使用 。 它可用于与以下模型的相互作用:
显示
-
创建显示
await api.client.display.create({ surveyId: "<your-survey-id>", // required userId: "<your-user-id>", // optional responseId: "<your-response-id>", // optional });
回应
-
创建响应
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 }); -
更新答复
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 });
联系人属性
-
更新联系人属性
await api.client.attribute.update({ userId: "<your-user-id>", // required attributes: { plan: "Pro", }, // required });
存储
-
上传文件
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 );
如果你有任何问题或需要帮助, 请随意联系我们 Github 讨论