import { Layout } from "@/components/docs/Layout";
import { Fence } from "@/components/shared/Fence";
import { APILayout } from "@/components/shared/APILayout.tsx";

export const meta = {
  title: "API: Update submission",
  description: "Learn how to update a new response to a survey via API.",
};

<APILayout
  method="POST"
  url="/api/v1/client/environments/{environmentId}/responses/{responseId}"
  description="Update an existing response in a survey."
  headers={[]}
  bodies={[
    {
      label: "customer",
      type: "JSON",
      description: "The customer and metadata you want to link the submission to.",
    },
    {
      label: "customer.email",
      type: "email",
      description: "Customer or user email. This is the primary key to identify users",
      required: true,
    },
    {
      label: "customer.prop",
      type: "string",
      description:
        "Pass value to create user property. You can filter / create cohorts for future surveys based on props.",
    },
    {
      label: "data",
      type: "JSON",
      description: "The content of the submission.",
    },
    {
      label: "data.fieldName",
      type: "string",
      description: "Add value to input field by name.",
      required: true,
    },
    {
      label: "finished",
      type: "boolean",
      description: "Determines if submission is marked as complete.",
    },
  ]}
  example={`{
  "response": {
    data: {
      "clfqjny0v0003yzgscnog1j9i": 10,
      "clfqjtn8n0070yzgs6jgx9rog": "I love Formbricks"
    },
    finished: true, // optional
  },
  "personId: "clfqjny0v000ayzgsycx54a2c",
  "surveyId": "clfqz1esd0000yzah51trddn8"
}`}
  responses={[
    {
      color: "green",
      statusCode: "200",
      description: "success",
      example: "{ // Response }",
    },
  ]}
/>

| field name | required | default | description                                                                                                                                                            |
| ---------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| response   | yes      | -       | The response object (answers to the survey). It requires a `data` object. In this object the key is the questionId, the value the answer of the user to this question. |

export default ({ children }) => <Layout meta={meta}>{children}</Layout>;
