mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-07 00:40:10 -06:00
feat: update client api docs as per new responses (#1695)
This commit is contained in:
committed by
GitHub
parent
c05433f4f9
commit
1280daafe3
@@ -45,14 +45,17 @@ Adds an Actions for a given User by their User ID
|
||||
curl --location --request POST 'https://app.formbricks.com/api/v1/client/<environment-id>/actions' \
|
||||
--data-raw '{
|
||||
"userId": "1",
|
||||
"name": "new_action_v2"
|
||||
"name": "new_action_v2",
|
||||
"properties":{}
|
||||
|
||||
}'
|
||||
```
|
||||
|
||||
```json {{ title: 'Example Request Body' }}
|
||||
{
|
||||
"userId": "1",
|
||||
"name": "new_action_v2"
|
||||
"name": "new_action_v3",
|
||||
"properties":{}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -65,12 +65,7 @@ This set of API can be used to
|
||||
```json {{title:'200 Success'}}
|
||||
{
|
||||
"data": {
|
||||
"id": "clp83r8uy000ceyqcbld2ebwj",
|
||||
"createdAt": "2023-11-21T08:57:23.866Z",
|
||||
"updatedAt": "2023-11-21T08:57:23.866Z",
|
||||
"surveyId": "cloqzeuu70000z8khcirufo60",
|
||||
"responseId": null,
|
||||
"personId": "cloo25v3e0000z8ptskh030jd"
|
||||
"id": "clphzz6oo00083zdmc7e0nwzi"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -81,7 +76,7 @@ This set of API can be used to
|
||||
"message": "Fields are missing or incorrectly formatted",
|
||||
"details": {
|
||||
"surveyId": "Required"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -129,14 +124,7 @@ This set of API can be used to
|
||||
|
||||
```json {{title:'200 Success'}}
|
||||
{
|
||||
"data": {
|
||||
"id": "clp83r8uy000ceyqcbld2ebwj",
|
||||
"createdAt": "2023-11-21T08:57:23.866Z",
|
||||
"updatedAt": "2023-11-21T09:05:27.285Z",
|
||||
"surveyId": "cloqzeuu70000z8khcirufo60",
|
||||
"responseId": null,
|
||||
"personId": "cloo25v3e0000z8ptskh030jd"
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -26,12 +26,6 @@ This set of API can be used to
|
||||
Create User with your own User ID
|
||||
|
||||
### Mandatory Request Body JSON Keys
|
||||
<Properties>
|
||||
<Property name="environmentId" type="string">
|
||||
Environment to create a person in
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Properties>
|
||||
<Property name="userId" type="string">
|
||||
User ID which you would like to identify the person with
|
||||
@@ -48,7 +42,6 @@ This set of API can be used to
|
||||
'https://app.formbricks.com/api/v1/client/<environment-id>/people' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"environmentId":"clonzr6vc0009z8md7y06hipl",
|
||||
"userId":"docs_user"
|
||||
}'
|
||||
```
|
||||
@@ -60,15 +53,7 @@ This set of API can be used to
|
||||
```json {{title:'200 Success'}}
|
||||
{
|
||||
"data": {
|
||||
"status": "success",
|
||||
"person": {
|
||||
"id": "clp861gvu0000v7wzr950fqad",
|
||||
"userId": "docs_user",
|
||||
"attributes": {},
|
||||
"environmentId": "clonzr6vc0009z8md7y06hipl",
|
||||
"createdAt": "2023-11-21T10:01:20.058Z",
|
||||
"updatedAt": "2023-11-21T10:01:20.058Z"
|
||||
}
|
||||
"userId": "docs_user"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -126,16 +111,7 @@ This set of API can be used to
|
||||
|
||||
```json {{title:'200 Success'}}
|
||||
{
|
||||
"data": {
|
||||
"id": "clp868htl0003v7wzmy977m15",
|
||||
"userId": "new_docs_user",
|
||||
"attributes": {
|
||||
"welcome_to": "formbricks"
|
||||
},
|
||||
"environmentId": "clonzr6vc0009z8md7y06hipl",
|
||||
"createdAt": "2023-11-21T10:06:47.865Z",
|
||||
"updatedAt": "2023-11-21T10:06:47.865Z"
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -95,29 +95,6 @@ Add a new response to a survey.
|
||||
{
|
||||
"data": {
|
||||
"id": "clp84xdld0002px36fkgue5ka",
|
||||
"createdAt": "2023-11-21T09:30:09.553Z",
|
||||
"updatedAt": "2023-11-21T09:30:09.553Z",
|
||||
"surveyId": "cloqzeuu70000z8khcirufo60",
|
||||
"finished": true,
|
||||
"data": {
|
||||
"clfqjny0v0003yzgscnog1j9i": 10,
|
||||
"clfqjtn8n0070yzgs6jgx9rog": "I love Formbricks"
|
||||
},
|
||||
"meta": {
|
||||
"userAgent": {}
|
||||
},
|
||||
"personAttributes": {},
|
||||
"singleUseId": null,
|
||||
"person": {
|
||||
"id": "cloo25v3e0000z8ptskh030jd",
|
||||
"userId": "1",
|
||||
"attributes": {},
|
||||
"environmentId": "clonzr6vc0009z8md7y06hipl",
|
||||
"createdAt": "2023-11-07T08:17:23.114Z",
|
||||
"updatedAt": "2023-11-07T08:17:23.114Z"
|
||||
},
|
||||
"tags": [],
|
||||
"notes": []
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -196,32 +173,7 @@ Update an existing response in a survey.
|
||||
|
||||
```json {{ title: '200 Success' }}
|
||||
{
|
||||
"data": {
|
||||
"id": "clp84xdld0002px36fkgue5ka",
|
||||
"createdAt": "2023-11-21T09:30:09.553Z",
|
||||
"updatedAt": "2023-11-21T09:35:38.357Z",
|
||||
"surveyId": "cloqzeuu70000z8khcirufo60",
|
||||
"finished": false,
|
||||
"data": {
|
||||
"clfqjny0v0003yzgscnog1j9i": 10,
|
||||
"clfqjtn8n0070yzgs6jgx9rog": "I love Formbricks"
|
||||
},
|
||||
"meta": {
|
||||
"userAgent": {}
|
||||
},
|
||||
"personAttributes": {},
|
||||
"singleUseId": null,
|
||||
"person": {
|
||||
"id": "cloo25v3e0000z8ptskh030jd",
|
||||
"userId": "1",
|
||||
"attributes": {},
|
||||
"environmentId": "clonzr6vc0009z8md7y06hipl",
|
||||
"createdAt": "2023-11-07T08:17:23.114Z",
|
||||
"updatedAt": "2023-11-07T08:17:23.114Z"
|
||||
},
|
||||
"tags": [],
|
||||
"notes": []
|
||||
}
|
||||
"data": {}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -34,10 +34,12 @@ export async function POST(request: Request, context: Context): Promise<NextResp
|
||||
|
||||
// find teamId & teamOwnerId from environmentId
|
||||
const teamDetails = await getTeamDetails(inputValidation.data.environmentId);
|
||||
let response = {};
|
||||
|
||||
// create display
|
||||
try {
|
||||
await createDisplay(inputValidation.data);
|
||||
const { id } = await createDisplay(inputValidation.data);
|
||||
response = { id };
|
||||
} catch (error) {
|
||||
if (error instanceof InvalidInputError) {
|
||||
return responses.badRequestResponse(error.message);
|
||||
@@ -53,5 +55,5 @@ export async function POST(request: Request, context: Context): Promise<NextResp
|
||||
console.warn("Posthog capture not possible. No team owner found");
|
||||
}
|
||||
|
||||
return responses.successResponse({}, true);
|
||||
return responses.successResponse(response, true);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { createPerson } from "@formbricks/lib/person/service";
|
||||
import { NextRequest } from "next/server";
|
||||
interface Context {
|
||||
params: {
|
||||
environmentId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function OPTIONS() {
|
||||
// cors headers
|
||||
@@ -8,11 +13,11 @@ export async function OPTIONS() {
|
||||
return responses.successResponse({}, true);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
export async function POST(req: NextRequest, context: Context) {
|
||||
// we need to create a new person
|
||||
// call the createPerson service from here
|
||||
|
||||
const { environmentId, userId } = await req.json();
|
||||
const environmentId = context.params.environmentId;
|
||||
const { userId } = await req.json();
|
||||
|
||||
if (!environmentId) {
|
||||
return responses.badRequestResponse("environmentId is required", { environmentId }, true);
|
||||
@@ -23,9 +28,9 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
const person = await createPerson(environmentId, userId);
|
||||
await createPerson(environmentId, userId);
|
||||
|
||||
return responses.successResponse({ status: "success", person }, true);
|
||||
return responses.successResponse({ userId }, true);
|
||||
} catch (err) {
|
||||
return responses.internalServerErrorResponse("Something went wrong", true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user