@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`,
environmentId: "<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>",
userId: "<your-user-id>",
responseId: "<your-response-id>",
});
Response
-
Create a Response
await api.client.response.create({
surveyId: "<your-survey-id>",
finished: boolean,
data: {
questionId: "<answer-to-this-question-in-string>",
anotherQuestionId: 123,
yetAnotherQuestionId: ["option1", "option2"],
},
userId: "<your-user-id>",
singleUseId: "<your-single-use-id>",
ttc: {
questionId: 123,
},
meta: {
source: "<your-source>",
url: "<your-url>",
userAgent: {
browser: "<your-browser>",
device: "<your-device>",
os: "<your-os>",
},
country: "<your-country>",
},
});
-
Update a Response
await api.client.response.update({
responseId: "<your-response-id>",
finished: boolean,
data: {
questionId: "<answer-to-this-question-in-string>",
anotherQuestionId: 123,
yetAnotherQuestionId: ["option1", "option2"],
},
ttc: {
questionId: 123,
},
});
Contact Attributes
-
Update contact attributes
await api.client.attribute.update({
userId: "<your-user-id>",
attributes: {
plan: "Pro",
},
});
Storage
-
Upload a file
await api.client.storage.uploadFile(
file: File,
{
allowedFileTypes: ["file-type-allowed", "for-example", "image/jpeg"],
surveyId: "<your-survey-id>",
}
);
If you have any questions or need help, feel free to reach out to us on Github Discussions