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",
};

<APILayout
  method="POST"
  url="/api/capture/forms/{formId}/submissions/{submissionId}"
  description="Update an existing submission in a form by form ID."
  queries={[{ label: "apiKey", type: "string", description: "Your API key" }]}
  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={`{
  "data": {
  "country": "Germany",
  },
  "customer": {
    "email": "hola@formbricks.com", // required
    "country": "Germany"
  },
  "finished": true
}`}
  responses={[
    {
      color: "green",
      statusCode: "200",
      description: "success",
      example: "{ // Response }",
    },
  ]}
/>

| field name | required | default | description                                                                                                                                                    |
| ---------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| data       | yes      | -       | The submission object (answers to the form/survey)                                                                                                             |
| customer   | no       | -       | The customer this submission is connected to. The customer object must contain an email field. All other fields are optional and get saved as user properties. |
| finished   | no       | false   | Mark a submission as complete to be able to filter accordingly                                                                                                 |

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