---
title: "Create an activity"
method: POST
path: "/activities"
tags: ["Activity Records"]
---

# Create an activity

`POST /activities`

## Request

- Base URL: `https://api.surense.com/api/v1`
- URL: `https://api.surense.com/api/v1/activities`
- Auth: OAuth 2
  - Client credentials
  - Token URL: `https://api.surense.com/oauth/token`

Logs a new activity record of the given activity type against exactly one parent entity.

**Parent entity.** At least one of `employerId`, `leadId`, `workflowId`, `customerId` or `meetingId` must be set. If several are set, only the first non-null one in that order is used (e.g. `employerId` wins over `customerId`). When the parent is a lead, the lead's customer is also linked; when it is a workflow or meeting, the related customer (and, for a meeting, lead) is linked as well.

**Authorization.** The caller must be able to access the parent entity and hold the user permission matching its type: `employers:write`, `leads:update`, `workflows:update`, `customers:update` or `meetings:update`. No OAuth2 scope beyond a valid token is required.

**Content.** `htmlContent` is sanitized (formatting, blocks, styles, images, links and tables are kept; scripts and other markup are stripped). A plain-text copy is stored for search. `jsonContent`, if set, is stored alongside it. `mentions` may only reference users of the caller's tenant.

**Side effects.** Publishes an `ActivityCreated` event (which notifies the mentioned users). The response is `200 OK` with the created record.

**Errors.** `404` if the activity type, the parent entity or a mentioned user does not exist in the caller's tenant; `400` if the request is invalid (no parent entity, missing type, empty content, invalid mentions), and `400` with error code `40000` if the caller lacks the required permission or access to the parent entity.

## Request body

- CreateActivityRequest: Request to create a new activity record. At least one parent ID (employerId, leadId, workflowId, customerId, meetingId) is required; if several are set, the first non-null in that order is used.
  - `typeId` string, required: ID of the activity type (must exist in the caller's tenant)
  - `employerId` string: Employer to log the activity against. Takes precedence over all other parent IDs; requires the employers:write permission.
  - `customerId` string: Customer to log the activity against. Used only when employerId, leadId and workflowId are null; requires the customers:update permission.
  - `leadId` string: Lead to log the activity against. Used only when employerId is null; requires the leads:update permission. The lead's customer is linked too.
  - `workflowId` string: Workflow to log the activity against. Used only when employerId and leadId are null; requires the workflows:update permission.
  - `meetingId` string: Meeting to log the activity against. Used only when all other parent IDs are null; requires the meetings:update permission.
  - `jsonContent` JsonNode: Rich-text content of the activity as JSON (the editor's document model), stored alongside htmlContent
    - `empty` boolean
    - `array` boolean
    - `null` boolean
    - `object` boolean
    - `float` boolean
    - `container` boolean
    - `string` boolean
    - `pojo` boolean
    - `floatingPointNumber` boolean
    - `short` boolean
    - `int` boolean
    - `long` boolean
    - `valueNode` boolean
    - `missingNode` boolean
    - `nodeType` 'ARRAY' | 'BINARY' | 'BOOLEAN' | 'MISSING' | 'NULL' | 'NUMBER' | 'OBJECT' | 'POJO' | 'STRING'
    - `integralNumber` boolean
    - `double` boolean
    - `bigDecimal` boolean
    - `bigInteger` boolean
    - `textual` boolean
    - `boolean` boolean
    - `binary` boolean
    - `number` boolean
    - `embeddedValue` boolean
  - `htmlContent` string, required: Activity content as HTML. Sanitized on save: formatting, blocks, styles, images, links and tables are kept, other markup is removed. Must not be blank.
  - `mentions` ActivityMention[]: Mentions present in the activity
    - `type` string
    - `entityId` string, uuid
    - `label` string
    - `order` integer

## Response `200`

The created activity record

- ActivityRecordValue: An activity record logged against an employer, customer, lead, workflow or meeting, with its replies and reactions
  - `tenantId` string, uuid
  - `createdDate` string, date-time
  - `createdBy` string, uuid
  - `creatorName` string
  - `lastModifiedDate` string, date-time
  - `lastModifiedBy` string, uuid
  - `version` integer
  - `id` string, uuid: Activity record ID
  - `typeId` string, uuid: ID of the activity type
  - `employerId` string, uuid: Employer the activity is logged against, if any
  - `customerId` string, uuid: Customer the activity is linked to, if any (also set for lead, workflow and meeting activities that relate to a customer)
  - `leadId` string, uuid: Lead the activity is linked to, if any
  - `workflowId` string, uuid: Workflow the activity is logged against, if any
  - `meetingId` string, uuid: Meeting the activity is logged against, if any
  - `activityDate` string, date-time: When the activity was logged (ISO-8601, UTC)
  - `jsonContent` JsonNode: Rich-text content of the activity as JSON (the editor's document model), stored alongside htmlContent
    - `empty` boolean
    - `array` boolean
    - `null` boolean
    - `object` boolean
    - `float` boolean
    - `container` boolean
    - `string` boolean
    - `pojo` boolean
    - `floatingPointNumber` boolean
    - `short` boolean
    - `int` boolean
    - `long` boolean
    - `valueNode` boolean
    - `missingNode` boolean
    - `nodeType` 'ARRAY' | 'BINARY' | 'BOOLEAN' | 'MISSING' | 'NULL' | 'NUMBER' | 'OBJECT' | 'POJO' | 'STRING'
    - `integralNumber` boolean
    - `double` boolean
    - `bigDecimal` boolean
    - `bigInteger` boolean
    - `textual` boolean
    - `boolean` boolean
    - `binary` boolean
    - `number` boolean
    - `embeddedValue` boolean
  - `htmlContent` string: Sanitized HTML content of the activity
  - `lastEditedAt` string, date-time: When the content was last edited (ISO-8601, UTC); null if never edited
  - `lastEditedBy` string, uuid: ID of the user who last edited the content; null if never edited
  - `reactions` ActivityReaction[]: Reactions of users on the activity, oldest first
    - `id` string, uuid
    - `userId` string, uuid
    - `userName` string
    - `reaction` string
    - `reactedAt` string, date-time
  - `replies` ActivityReply[]: Replies to the activity, oldest first
    - `id` string, uuid
    - `userId` string, uuid
    - `userName` string
    - `jsonContent` JsonNode: Rich-text content of the activity as JSON (the editor's document model), stored alongside htmlContent
      - `empty` boolean
      - `array` boolean
      - `null` boolean
      - `object` boolean
      - `float` boolean
      - `container` boolean
      - `string` boolean
      - `pojo` boolean
      - `floatingPointNumber` boolean
      - `short` boolean
      - `int` boolean
      - `long` boolean
      - `valueNode` boolean
      - `missingNode` boolean
      - `nodeType` 'ARRAY' | 'BINARY' | 'BOOLEAN' | 'MISSING' | 'NULL' | 'NUMBER' | 'OBJECT' | 'POJO' | 'STRING'
      - `integralNumber` boolean
      - `double` boolean
      - `bigDecimal` boolean
      - `bigInteger` boolean
      - `textual` boolean
      - `boolean` boolean
      - `binary` boolean
      - `number` boolean
      - `embeddedValue` boolean
    - `htmlContent` string
    - `createdAt` string, date-time
    - `updatedAt` string, date-time
    - `mentions` ActivityMention[]
      - `type` string
      - `entityId` string, uuid
      - `label` string
      - `order` integer
    - `reactions` ActivityReaction[]
      - `id` string, uuid
      - `userId` string, uuid
      - `userName` string
      - `reaction` string
      - `reactedAt` string, date-time

## Other responses

- `400`: Invalid request (no parent entity, missing type, empty content, invalid mentions), or (error code 40000) missing permission for the parent entity type or the parent entity is not accessible
- `404`: Activity type, parent entity or mentioned user not found

---

[API](https://skmtc.dev/surense/apis/activity-api.md) - [All operations](https://skmtc.dev/surense/apis/activity-api/llms.txt) - [OpenAPI document](https://skmtc.dev/surense/apis/activity-api/revisions/1fa9c003b93b?raw)
