import { MdxImage } from "@/components/MdxImage";
export const metadata = {
title: "Formbricks API SDK",
description:
"An overview of all available methods & how to integrate Formbricks API for backend developers in web applications. Learn the key methods, configuration settings, and best practices.",
};
#### Developer Docs
# SDK: Formbricks API
### Overview
The Formbricks Client API Wrapper is a lightweight package designed to simplify the integration of Formbricks API endpoints into your JavaScript (JS) or TypeScript (TS) projects. With this wrapper, you can easily interact with Formbricks API endpoints without the need for complex setup or manual HTTP requests.
### Install
```js {{ title: 'npm' }}
npm install @formbricks/api
```
```js {{ title: 'yarn' }}
yarn add @formbricks/api
```
```js {{ title: 'pnpm' }}
pnpm add @formbricks/api
```
## Methods
### Initialize Formbricks
Initialize the Formbricks API Client for backend developers to interact with Formbricks API endpoints:
```javascript
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: "", // 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:
## Displays
- Create Display
```javascript {{ title: 'Create Display Method Call'}}
await api.client.display.create({
surveyId: "", // required
userId: "", // optional
responseId: "", // optional
});
```
```javascript {{ title: 'Create Display Method Return Type' }}
Promise<{ id: string }, NetworkError | Error>
```
- Update Display
```javascript {{ title: 'Update Display Method Call'}}
await api.client.display.update(
displayId: "",
{
userId: "", // optional
responseId: "", // optional
},
);
```
```javascript {{ title: 'Update Display Method Return Type' }}
Promise<{ }, NetworkError | Error]>
```
## Responses
- Create Response
```javascript {{ title: 'Create Response Method Call'}}
await api.client.response.create({
surveyId: "", // required
finished: boolean, // required
data: {
// required
questionId: "",
anotherQuestionId: 123, // answer to this question in number
yetAnotherQuestionId: ["option1", "option2"], // answer to this question in array,
},
userId: "",
singleUseId: "",
ttc: {
questionId: 123,
},
meta: {
source: "",
url: "",
userAgent: {
browser: "",
device: "",
os: "",
},
country: "",
},
});
```
```javascript {{ title: 'Create Response Method Return Type' }}
Promise<{ id: string }, NetworkError | Error>
```
- Update Response
```javascript {{ title: 'Update Response Method Call'}}
await api.client.response.update({
responseId: "", // required
finished: boolean, // required
data: {
// required
questionId: "",
anotherQuestionId: 123, // answer to this question in number
yetAnotherQuestionId: ["option1", "option2"], // answer to this question in array,
},
ttc: {
// required
questionId: 123,
},
});
```
```javascript {{ title: 'Update Response Method Return Type' }}
Promise<{ }, NetworkError | Error]>
```
## Action
- Create Action:
An environment cannot have 2 actions with the same name.
```javascript {{ title: 'Create Action Method Call'}}
await api.client.action.create({
name: "", // required
userId: "", // required
});
```
```javascript {{ title: 'Create Action Method Return Type' }}
Promise<{ }, NetworkError | Error]>
```
## Attribute
- Update Attribute
```javascript {{ title: 'Update Attribute Method Call'}}
await api.client.attribute.update({
userId: "", // required
attributes: {
key1: "value1",
key2: "value2",
}, // required
});
```
```javascript {{ title: 'Update Attribute Method Return Type' }}
Promise<{ changed: boolean, message: string }, NetworkError | Error>
```
## People
- Create Person
```javascript {{ title: 'Create Person Method Call'}}
await api.client.people.create({
userId: "", // required
});
```
```javascript {{ title: 'Create Person Method Return Type' }}
Promise<{ }, NetworkError | Error]>
```
## Storage
- Upload File:
```javascript {{ title: 'Upload Method Call'}}
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"],
surveyId: "",
}
);
```
```javascript {{ title: 'Upload Method Return Type' }}
Promise
```
---
If you have any questions or need help, feel free to reach out to us on our **[Discord](https://formbricks.com/discord)**