Tasks Batch Create Post Limit?

Hi everybody,

I’m trying to batch create tasks using this endpoint /crm/v3/objects/tasks/batch/create (Accounts Dashboard | HubSpot).

I started by creating 100 tasks with each batch, but everything came back with status code 400. I then tried 10 at a time, and some went through with 201 or 200, but others still got 400.

Is there a size limit for post requests to this endpoint? The “hs_task_body” is quite long for some of the tasks, so that was my first idea.

This is the error message I get:

{“status”:“error”,“message”:“Invalid input JSON on line 1, column 434. Some required fields were not set: [id]”,“correlationId”:“56a13ba3-1a01-4103-9eae-7ecfd0f81ac8”,“category”:“VALIDATION_ERROR”}

The text body shown in the private app on Hubspot for requests that get a 400 answer is always limited to 2000 character, but I don’t know if that’s a limit of the display field or it gets cut off from the post request.

I’m using the Python requests library (requests · PyPI), if that helps in any way.

Thanks in advance for any help,

Simon

Hello @flaugers
The batch create endpoint for tasks has a limit of 100 tasks per request. This is because the endpoint uses a single HTTP request to create multiple tasks, and each HTTP request has a maximum size limit. If you try to create more than 100 tasks in a single request, you will receive a 400 Bad Request error.
To create more than 100 tasks in a single batch, you can use the following steps
Create a list of tasks to create.
Use the batch create endpoint to create the tasks in batches of 100.
Repeat steps 1 and 2 until all tasks have been created.
The following code shows how to create a batch of tasks using the Python requests library

import requests

# Create a list of tasks to create.
tasks = [
 {
 "title": "Task 1",
 "due_date": "2023-06-01",
 },
 {
 "title": "Task 2",
 "due_date": "2023-06-02",
 },
 {
 "title": "Task 3",
 "due_date": "2023-06-03",
 },
]

# Create a request object for the batch create endpoint.
url = "https://api.hubspot.com/crm/v3/objects/tasks/batch/create"
headers = {
 "Authorization": "Bearer YOUR_ACCESS_TOKEN",
}

# Create a JSON object containing the tasks to create.
payload = {
 "tasks": tasks,
}

# Send the request to create the tasks.
response = requests.post(url, headers=headers, data=payload)

# Check the response status code.
if response.status_code == 200:
 # The tasks were created successfully.
 print("Tasks created successfully.")
else:
 # An error occurred.
 print("An error occurred creating the tasks.")

This code will create three tasks with the titles “Task 1”, “Task 2”, and “Task 3”. The tasks will have a due date of June 1, 2023, June 2, 2023, and June 3, 2023, respectively.

Hi @himanshurauthan ,

thanks for the quick reply. I am, however, already creating the tasks in batches. As mentioned above, I tried it with 100, then with 10, and a third time with 5 tasks per batch. Each time more of the requests were successfull, but not all.

Is there another limit on the request size?

Hi @flaugers

The error message you received indicates that there are some required fields missing in the input JSON for the tasks you’re trying to create. The “id” field is specifically mentioned as a missing required field.
Regarding the size limit for POST requests to the `/crm/v3/objects/tasks/batch/create` endpoint, HubSpot does have some limits in place. The maximum payload size for a single request is 3MB, including headers and the request body. However, it’s unlikely that you’re exceeding this limit if you’re only creating a few tasks at a time.
To troubleshoot the issue, here are a few suggestions:
1. Verify the JSON structure: Ensure that the JSON payload you’re sending adheres to the correct structure expected by the API. Make sure that the required fields, such as `id`, are included for each task.
2. Check the content length: If the `hs_task_body` field is quite long, it’s possible that you’re exceeding the character limit for the field. The HubSpot API has limits on the size of individual properties, so you may need to truncate or shorten the `hs_task_body` value if it exceeds the limit. Refer to the API documentation or contact HubSpot support to determine the specific limit for the `hs_task_body` field.
3. Test individual task creation: Instead of using batch create, try creating tasks one by one using the `/crm/v3/objects/tasks` endpoint. This will help you identify if there’s a specific task causing the issue.
4. Validate your JSON payload: You can use online JSON validators or tools to validate your JSON payload and ensure it is well-formed and contains all the required fields.
Regarding the text body being limited to 2000 characters in the HubSpot app, it’s possible that it’s a display limitation in the user interface and not related to the actual request payload.
If the issue persists, I recommend reaching out to HubSpot support for further assistance. They will be able to help you troubleshoot the specific error and provide guidance on resolving it.

Hope this will helps you out. Please mark it as Solution Accepted to help other Community member.
Thanks!