# Subscribe to an entity

`POST /api/entity-subscription`

Creates a new subscription for an entity using the provided subscription details.

Authentication (security requirement alternatives):

```json
[
  {
    "bearer": []
  }
]
```

- bearer: http (bearer), header JWT. Enter JWT token

Request body: application/json (required)

The subscription details for creating a new entity subscription.

Type: object

Schema: [CreateEntitySubscriptionDTO](https://sourcey-gauzy.pages.dev/api-reference/models/createentitysubscriptiondto/index.md)

- `tenant` (optional)
  Type: object

- `tenantId` (optional)
  Type: string

- `organization` (required)
  Type: object

- `organizationId` (required)
  Type: string

- `sentTo` (optional)
  Type: string

- `entity` (required)
  Type: string
  
  enum: ["Broadcast","Candidate","Comment","Contact","Currency","DailyPlan","Dashboard","DashboardWidget","Document","Employee","Expense","Invoice","Income","Language","Organization","OrganizationContact","OrganizationDepartment","OrganizationDocument","OrganizationProject","OrganizationTeam","OrganizationProjectModule","OrganizationSprint","OrganizationVendor","ResourceLink","ScreeningTask","OrganizationStrategicInitiative","Task","TaskLinkedIssue","TaskView","User","Tenant"]

- `entityId` (required)
  Type: string

- `actorType` (optional)
  Type: string
  
  enum: ["System","User"]

- `type` (required)
  Type: string
  
  enum: ["manual","mention","assignment","comment","created-entity"]

Responses:

- 201: The record has been successfully created.

Content type: application/json

Type: object

Schema: [EntitySubscription](https://sourcey-gauzy.pages.dev/api-reference/models/entitysubscription/index.md)

- `deletedAt` (optional)
  Type: string, date-time
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `createdAt` (optional)
  Type: string, date-time
  
  The creation timestamp of the entity.
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `updatedAt` (optional)
  Type: string, date-time
  
  The last update timestamp of the entity.
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `id` (optional)
  Type: string

- `isActive` (optional)
  Type: boolean
  
  default: true

- `isArchived` (optional)
  Type: boolean
  
  default: false

- `archivedAt` (optional)
  Type: string, date-time
  
  Example:
  
  ```json
  "2018-11-21T06:20:32.232Z"
  ```

- `tenantId` (optional)
  Type: string

- `organizationId` (optional)
  Type: string

- `entity` (required)
  Type: string
  
  enum: ["Broadcast","Candidate","Comment","Contact","Currency","DailyPlan","Dashboard","DashboardWidget","Document","Employee","Expense","Invoice","Income","Language","Organization","OrganizationContact","OrganizationDepartment","OrganizationDocument","OrganizationProject","OrganizationTeam","OrganizationProjectModule","OrganizationSprint","OrganizationVendor","ResourceLink","ScreeningTask","OrganizationStrategicInitiative","Task","TaskLinkedIssue","TaskView","User","Tenant"]

- `entityId` (required)
  Type: string

- `actorType` (optional)
  Type: string
  
  enum: ["System","User"]

- `type` (required)
  Type: string
  
  enum: ["manual","mention","assignment","comment","created-entity"]

- `employee` (optional)
  Reference: [Employee](https://sourcey-gauzy.pages.dev/api-reference/models/employee/index.md); Type: object

- `employeeId` (optional)
  Type: string

- 400: Invalid input. The response body may contain clues as to what went wrong.

- 401: Unauthorized

- 403: Forbidden

## Examples

### cURL

```bash
curl -X POST 'http://localhost:3000/api/entity-subscription' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "tenant": {},
  "tenantId": "string",
  "organization": {},
  "organizationId": "string",
  "sentTo": "string",
  "entity": "Broadcast",
  "entityId": "string",
  "actorType": "System",
  "type": "manual"
}'
```

### JavaScript

```javascript
const body = `{
  "tenant": {},
  "tenantId": "string",
  "organization": {},
  "organizationId": "string",
  "sentTo": "string",
  "entity": "Broadcast",
  "entityId": "string",
  "actorType": "System",
  "type": "manual"
}`;

const response = await fetch('http://localhost:3000/api/entity-subscription', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "tenant": {},
  "tenantId": "string",
  "organization": {},
  "organizationId": "string",
  "sentTo": "string",
  "entity": "Broadcast",
  "entityId": "string",
  "actorType": "System",
  "type": "manual"
}'''

response = requests.post(
    'http://localhost:3000/api/entity-subscription',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
