Skip to content

Commit

Permalink
fix: add missing docs for update survey endpoint (formbricks#1652)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamPalriwala authored Nov 22, 2023
1 parent dae8aaa commit 7e68a5e
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
116 changes: 116 additions & 0 deletions apps/formbricks-com/app/docs/api/management/surveys/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This set of API can be used to
- [List All Surveys](#list-all-surveys)
- [Get Survey](#get-survey-by-id)
- [Create Survey](#create-survey)
- [Update Survey](#update-survey-by-id)
- [Delete Survey](#delete-survey-by-id)

<Note>You will need an API Key to interact with these APIs.</Note>
Expand Down Expand Up @@ -472,6 +473,121 @@ This set of API can be used to

---

## Update Survey by ID {{ tag: 'PUT', label: '/api/v1/management/surveys/<survey-id>' }}

<Row>
<Col>

Update a survey by its ID

### Mandatory Headers

<Properties>
<Property name="x-Api-Key" type="string">
Your Formbricks API key.
</Property>
</Properties>

### Body

<CodeGroup title="Request Body">
```json {{ title: 'cURL' }}
{
"name": "My renamed Survey",
"redirectUrl":"https://formbricks.com",
"type":"web"
}
```
</CodeGroup>


</Col>
<Col sticky>

<CodeGroup title="Request" tag="PUT" label="/api/v1/management/surveys/<survey-id>">

```bash {{ title: 'cURL' }}
curl -X POST https://app.formbricks.com/api/v1/management/surveys/<survey-id> \
--header 'Content-Type: application/json' \
--header 'x-api-key: <your-api-key>' \
-d '{"name": "My renamed Survey"}'
```

</CodeGroup>

<CodeGroup title="Response">

```json {{title:'200 Success'}}
{
"data": {
"id": "cloqzeuu70000z8khcirufo60",
"createdAt": "2023-11-09T09:23:42.367Z",
"updatedAt": "2023-11-09T09:23:42.367Z",
"name": "My renamed Survey",
"redirectUrl": null,
"type": "link",
"environmentId": "clonzr6vc0009z8md7y06hipl",
"status": "inProgress",
"welcomeCard": {
"html": "Thanks for providing your feedback - let's go!",
"enabled": false,
"headline": "Welcome!",
"timeToFinish": false
},
"questions": [
{
"id": "l9rwn5nbk48y44tvnyyjcvca",
"type": "openText",
"headline": "Why did you leave the platform?",
"required": true,
"inputType": "text"
}
],
"thankYouCard": {
"enabled": true,
"headline": "Thank you!",
"subheader": "We appreciate your feedback."
},
"hiddenFields": {
"enabled": true,
"fieldIds": []
},
"displayOption": "displayOnce",
"recontactDays": null,
"autoClose": null,
"delay": 0,
"autoComplete": 50,
"closeOnDate": null,
"surveyClosedMessage": null,
"productOverwrites": null,
"singleUse": {
"enabled": false,
"isEncrypted": true
},
"verifyEmail": null,
"pin": null,
"triggers": [],
"attributeFilters": []
}
}
```

```json {{ title: '401 Not Authenticated' }}
{
"code": "not_authenticated",
"message": "Not authenticated",
"details": {
"x-Api-Key": "Header not provided or API Key invalid"
}
}
```
</CodeGroup>

</Col>
</Row>

---


## Delete Survey by ID {{ tag: 'DELETE', label: '/api/v1/management/surveys/<survey-id>' }}

Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/api/v1/management/surveys/[surveyId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export async function PUT(
return responses.notFoundResponse("Survey", params.surveyId);
}
const surveyUpdate = await request.json();
const inputValidation = ZSurvey.safeParse(surveyUpdate);
const inputValidation = ZSurvey.safeParse({
...survey,
...surveyUpdate,
});
if (!inputValidation.success) {
return responses.badRequestResponse(
"Fields are missing or incorrectly formatted",
Expand Down

0 comments on commit 7e68a5e

Please sign in to comment.