Files
formbricks/packages/api
Shubham Palriwala 769ceb1fc2 refactor: @formbricks/api package (#782)
* init: rewritten formbricks api package

* restrucure: client prepended formbricks api package

* feat: cleanup error templating and node-fetch for non browser access

* feat: replace package (build error for js packge due to api)

* fix: rename methods & move error type

* fix: imports of api via js

* remove node-fetch

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-10-01 11:50:29 +02:00
..
2023-06-28 13:07:51 +02:00

@formbricks/api - API Wrapper for Formbricks

Installation

npm install @formbricks/api

Usage

Create API Client
import { FormbricksAPI, EnvironmentId } from "@formbricks/api";

const api = new FormbricksAPI({
  apiHost: "http://localhost:3000",
  environmentId: "clgwh8maj0005n2f66pwzev3r" as EnvironmentId,
});

Note

All of the following methods return a Result from the @formbricks/errors package.

Create a new response
const response = await api.createResponse({
  surveyId: "......" as SurveyId,
  personId: "......" as PersonId,
  data: {
    questionId: "response",
  },
});
Update an existing response
const response = await api.updateResponse({
  responseId: "......" as ResponseId, // If you pass response.value.id from createResponse, you dont need 'as ResponseId'
  data: {
    questionId: "response",
  },
});