# Create comment

POST /comments. Parameters, permissions, request and response schemas.

`POST /comments`

Create comment. Requires the REST `write` token ability. The bearer token selects the Team; a supplied team\_id cannot switch tenants. Additional role, entity-policy and plan requirements vary by operation. A Team in blocked billing mode cannot write and receives 402.

## Authentication

Use a team API key as `Authorization: Bearer YOUR_API_KEY`. The token ability and the user’s role must both allow this operation. See [authentication](https://conversionlab.app/docs/developer/authentication).

```json
{
  "ability": "write",
  "team": "Token-bound Team",
  "authorization": "Additional role, entity-policy and plan requirements vary by operation.",
  "billing": "Blocked billing mode rejects writes with 402."
}
```

## Request body

A request body is required.

### application/json

```json
{
  "type": "object",
  "properties": {
    "commentable_type": {
      "type": "string",
      "enum": [
        "insight",
        "idea",
        "experiment"
      ]
    },
    "commentable_id": {
      "type": "integer",
      "minimum": 1
    },
    "body": {
      "type": "string",
      "maxLength": 5000
    },
    "parent_id": {
      "type": [
        "integer",
        "null"
      ]
    }
  },
  "required": [
    "commentable_type",
    "commentable_id",
    "body"
  ],
  "title": "StoreCommentRequest"
}
```

```json
{
  "commentable_type": "insight",
  "commentable_id": 101,
  "body": "example"
}
```

## Example request

```bash
curl --request POST 'https://api.example.test/api/comments' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"commentable_type":"insight","commentable_id":101,"body":"example"}'
```

Examples use fictional data. Replace resource IDs and the API host with your environment’s values.

## Responses

### 201

`CommentResource`

Content type: `application/json`.

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "body": {
          "type": "string"
        },
        "user": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                },
                "email": {
                  "type": "string"
                },
                "role": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "seat_type": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "email_verified_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "created_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "updated_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "last_login_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                }
              },
              "required": [
                "id",
                "name",
                "email",
                "role",
                "seat_type",
                "email_verified_at",
                "created_at",
                "updated_at",
                "last_login_at"
              ],
              "title": "UserResource"
            },
            {
              "type": "null"
            }
          ]
        },
        "user_id": {
          "type": [
            "integer",
            "null"
          ]
        },
        "parent_id": {
          "type": [
            "integer",
            "null"
          ]
        },
        "replies": {
          "type": "array",
          "items": {
            "$ref": "#/components/schemas/CommentResource"
          }
        },
        "is_approved": {
          "type": "boolean"
        },
        "commentable_type": {
          "type": "string"
        },
        "commentable_id": {
          "type": "integer"
        },
        "can_edit": {
          "type": "boolean"
        },
        "can_delete": {
          "type": "boolean"
        },
        "created_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      },
      "required": [
        "id",
        "body",
        "user_id",
        "parent_id",
        "is_approved",
        "commentable_type",
        "commentable_id",
        "can_edit",
        "can_delete",
        "created_at",
        "updated_at"
      ],
      "title": "CommentResource"
    }
  },
  "required": [
    "data"
  ]
}
```

```json
{
  "data": {
    "id": 101,
    "body": "example",
    "user_id": null,
    "parent_id": null,
    "is_approved": true,
    "commentable_type": "example",
    "commentable_id": 101,
    "can_edit": true,
    "can_delete": true,
    "created_at": null,
    "updated_at": null
  }
}
```

### 401

Unauthenticated

Content type: `application/json`.

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "Error overview."
    }
  },
  "required": [
    "message"
  ]
}
```

```json
{
  "message": "The request could not be completed."
}
```

### 402

The Team is in read-only billing mode.

Content type: `application/json`.

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "string",
      "const": "subscription_required"
    },
    "mode": {
      "type": "string",
      "const": "blocked"
    },
    "message": {
      "type": "string",
      "example": "Your team is in read-only mode. Update billing to make changes."
    },
    "grace_period_ends_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "required": [
    "error",
    "mode",
    "message",
    "grace_period_ends_at"
  ]
}
```

```json
{
  "error": "subscription_required",
  "mode": "blocked",
  "message": "Your team is in read-only mode. Update billing to make changes.",
  "grace_period_ends_at": null
}
```

### 403

Authorization error

Content type: `application/json`.

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "Error overview."
    }
  },
  "required": [
    "message"
  ]
}
```

```json
{
  "message": "The request could not be completed."
}
```

### 422

Validation error

Content type: `application/json`.

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "Errors overview."
    },
    "errors": {
      "type": "object",
      "description": "A detailed description of each field that failed validation.",
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    }
  },
  "required": [
    "message",
    "errors"
  ]
}
```

```json
{
  "message": "The request could not be completed.",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

### 429

Rate limit exceeded. Honor Retry-After before retrying.

Response headers:

```json
{
  "Retry-After": {
    "description": "Seconds before retrying.",
    "schema": {
      "type": "integer"
    }
  }
}
```

Content type: `application/json`.

```json
{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "example": "Too Many Attempts."
    }
  },
  "required": [
    "message"
  ]
}
```

```json
{
  "message": "Too Many Attempts."
}
```

See [API conventions](https://conversionlab.app/docs/developer/api-conventions) for error handling, rate limits, pagination, and uploads.
