# Add or Update Activity

## Add or Update Activity which belongs contact, company, opportunity and lead

<mark style="color:green;">`POST`</mark> `[PlatformAddress]/api/1.0/crm?action=addOrUpdateActivity`

#### Path Parameters

| Name           | Type      | Description                                                                                                                                                   |
| -------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id             | integer   | The unique id of the activity                                                                                                                                 |
| venueId        | integer   | The unique id of the venue to which the activity belongs. Required when assigning the activity to opportunity. The api will throw an error for invalid leadId |
| leadId         | integer   | The unique id of the opportunity/lead to which the new activity belongs                                                                                       |
| contactId      | integer   | The unique id of the contact to which the new activity belongs                                                                                                |
| companyId      | integer   | The unique id of the company to which the new activity belongs                                                                                                |
| name           | string    | The name of the activity. Required when id is missing.                                                                                                        |
| description    | string    | The description of the activity. Required when id is missing.                                                                                                 |
| subType        | integer   | The subtype of activity. Required when id is missing.                                                                                                         |
| purposeId      | integer   | The unique id of the venue to which the booking belongs                                                                                                       |
| startDatetime  | timestamp | The start date and time of the activity. Format is Y-m-d H:i:s and must be in UTC timezone.                                                                   |
| endDatetime    | timestamp | The end date and time of the activity. Format is Y-m-d H:i:s and must be in UTC timezone.                                                                     |
| location       | string    | The location of the event activity                                                                                                                            |
| priority       | string    | The priority of the activity low, medium or high.                                                                                                             |
| assignedUserId | integer   | The unique id of the user to which the activity will be assigned                                                                                              |

{% tabs %}
{% tab title="200 " %}

```
{
  "success": true,
  "id": 755
}
```

{% endtab %}
{% endtabs %}

## Activity Sub Type

| Id | Name    |
| -- | ------- |
| 1  | Meeting |
| 2  | Call    |
| 3  | Email   |

## Example Request

### Add Activity

```javascript
{
  "name": "Test Activity API",
  "venueId": 1,
  "subType": 2,
  "purposeId": 1,
  "startDateTime": "2020-02-02 01:00:00 UTC",
  "endDateTime": "2020-02-02 02:00:00 UTC",
  "assignedUserId": 1,
  "leadId": 2665
}
```

### Update Activity

```javascript
{
  "id": 3269,
  "venueId": 1,
  "name": "Test Activity API"
}
```

## Returns

| Property | Description                                   |
| -------- | --------------------------------------------- |
| success  | Whether or not the activity was added/updated |
| id       | The unique id of the activity                 |

## Throws

| Code                 | Description                                                                                                       |
| -------------------- | ----------------------------------------------------------------------------------------------------------------- |
| Specific Code: 24397 | The lead/opportunity does not exist                                                                               |
| Specific Code: 24398 | The contact does not exist                                                                                        |
| Specific Code: 24399 | The company does not exist                                                                                        |
| Specific Code: 24400 | The activity does not exist                                                                                       |
| Specific Code: 24401 | An error has occurred                                                                                             |
| Specific Code: 24402 | The request contains invalid data. The data was validated but there was some other error. See additional messages |
| Specific Code: 24403 | The request contains invalid data                                                                                 |
| Specific Code: 24404 | The activity can only belongs to either contact, company or opportunity/lead                                      |

Activity can only belongs to either company, contact or lead. When companyId and contactId both provided the contactId will be added to company as company contact and activity will be be associated with company.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.ivvy.com/crm/add-or-update-activity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
