Error when posting/creating datetime property (HTTP 400 error)

When trying to create the datetime property, here’s the error I get. Can someone help??

HTTP 400 { “status”: “error”, “message”: “Property failed validation.”, “correlationId”: “cd9d4de0-6715-46b2-97e0-70ac559142e3”, “category”: “VALIDATION_ERROR”, “subCategory”: “Properties.PROPERTY_CREATE_FAILED_VALIDATION” }

Here’s my input:

curl --request POST \
--url https://api.hubapi.com/crm/v3/properties/contacts \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“hidden”: false,
“displayOrder”: 2,
“description”: “datetime”,
“label”: “DateTime”,
“type”: “datetime”,
“groupName”: “contactinformation”,
“name”: “datetime”,
“fieldType”: “date”,
“formField”: true,
“referencedObjectType”: “string”,
“calculationFormula”: “string”,
“hasUniqueValue”: false,
“externalOptions”: true
}’

Hi @CMyhra

Please find the technicals of the HTTP 400

New validation for custom object names (hubspot.com)

Custom object schemas

CRM | custom objects (hubspot.com)

Kindly to trouble shoot and keep us posted for additional assistance.

Hope this helps - Happy to help further!!
Thank you very much and have a great one!

Warm regards

Hello @CMyhra , i have EXACTLY the same error when trying to post a new datetime property. Do you have a solution ?

Hi @CMyhra - Kindly take a look in to my recent response and code and see if that helps

Was a solution found for this issue?
The error message is not helpful. I am having the same issue, trying to create a datetime property on contacts.

Hi @ADitlevsen

Kindly take a look in to my recent response and code and see if that helps

Yeah, I am also having the same issues. I can’t find any reason why the validation would fail. I have done this many times in the past. Not sure if there has been a change in the validation requirements?

Hi @GIlievski

Per @CMyhra code,

When I closely looked in to the code, noticed the inconsistency between type and fieldType:

  • The type “datetime” which is correct for a datetime property.
  • However, the fieldType is set to “date”. This field type expects only date information (year, month, day) and not time.

Can you try change the fieldType to “datetime” to match the type – a sample code reference is given below

JSON

{

“hidden”: false,

“displayOrder”: 2,

“description”: “datetime”,

“label”: “DateTime”,

“type”: “datetime”,

“groupName”: “contactinformation”,

“name”: “datetime”,

“fieldType”: “datetime”, // Change here

“formField”: true,

“referencedObjectType”: “string”,

“calculationFormula”: “string”,

“hasUniqueValue”: false,

“externalOptions”: true

}

Regards

Hello,
I am facing the same issue and when I try to select Datetime as Field Type I cannot find it among the available options:

Thanks,

Aalaa

Hey Aalaa,

You can now create them with the UI. There is a free beta for any HubSpot tier.

Just replace your portal ID in the link below and opt into the beta.

https://app.hubspot.com/product-updates/[portalID]/?update=13941230

Hello Goran,

Thanks for your response.

Yes, for the property type I don’t face any issues, I select datetime:

I mean after I select the type parameter, there is another parameter called fieldTypeI don’t find the same “datetime” in fieldType:

I followed the link you provided and joined the beta, but it’s still the same, gives me validation error for all the fieldTypes that I tried since they don’t match the Type (datetime):
curl --request POST \
--url https://api.hubapi.com/crm/v3/properties/contacts \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“hidden”: false,
“displayOrder”: 2,
“description”: “string”,
“label”: “DateTime Test”,
“type”: “datetime”,
“groupName”: “contactinformation”,
“name”: “datetimetest”,
“fieldType”: “date”,
“formField”: true,
“referencedObjectType”: “string”,
“options”: [
{
“label”: “Option A”,
“value”: “A”,
“hidden”: false,
“description”: “Choice number one”,
“displayOrder”: 1
},
{
“label”: “Option B”,
“value”: “B”,
“hidden”: false,
“description”: “Choice number two”,
“displayOrder”: 2
}
],
“calculationFormula”: “string”,
“hasUniqueValue”: false,
“externalOptions”: true
}’

Hello Goran,

thanks for your response!

Yes when I try to select “datetime” for the Type Parameter, that works fine:

However, what I mean is after that, I have to also select the fieldType parameter, that one doesn’t have the datetime option even after I joined the beta and followed the stepsyou provided:

Please find the request below, which gives me a validation error:

curl --request POST \
--url https://api.hubapi.com/crm/v3/properties/contacts \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“hidden”: false,
“displayOrder”: 2,
“description”: “string”,
“label”: “DateTime Test”,
“type”: “datetime”,
“groupName”: “contactinformation”,
“name”: “datetimetest”,
“fieldType”: “textarea”,
“formField”: true,
“referencedObjectType”: “string”,
“options”: [
{
“label”: “Option A”,
“value”: “A”,
“hidden”: false,
“description”: “Choice number one”,
“displayOrder”: 1
},
{
“label”: “Option B”,
“value”: “B”,
“hidden”: false,
“description”: “Choice number two”,
“displayOrder”: 2
}
],
“calculationFormula”: “string”,
“hasUniqueValue”: false,
“externalOptions”: true
}’

Thanks,

Aalaa

Hey Aalaa,

The beta now allows you to create Date Time in the HubSpot UI, it has nothing to do with the API. So you would go to create a new property and then choose Datetime

As for the API creation, the “fieldType” parameter never had DateTime as an option, it always stays as Date. Only the “type” needs to be DateTime.

From your request I can see you have selected “textarea” as fieldType, that should be “Date”. Also make sure you have delete all the “Options” and leave blank the fields “reference object type” and “calculation formula”.

@GIlievski If incase you can share your code, i can look in to the actual issue - the below solution may not be the solution for yours.

Thanks @Humashankar
We are trying to create a property for Contacts, so it has nothing to do with custom objects.
Also, the type can be “datetime” or “date”, but the fieldType can only be “date”.
If you go to this link Accounts Dashboard | HubSpot under Endpoints > Create Property (Core) you can see the values for both Type and Field Type. They are dropdown values.
Again I have done this a few times in the past but something might have changed.

Okay I solved my issue, not sure if it will help you @ADitlevsen @CMyhra @HSchaefer9
All I did was leave blank the fields “reference object type” and “calculation formula” and it worked.
I did use the new Beta docs, not that it matters.
cc @Humashankar

Hello I’m trying to add a datetime property inside Deals but I’m getting some error

curl --request POST \
--url https://api.hubapi.com/crm/v3/properties/string \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“hidden”: false,
“displayOrder”: 2,
“description”: “Depart Time Date”,
“label”: “Depart Time Date”,
“type”: “datetime”,
“groupName”: “dealinformation”,
“name”: “departdatetime”,
“fieldType”: “date”,
“formField”: false,
“referencedObjectType”: “string”,
“calculationFormula”: “string”,
“hasUniqueValue”: false,
“externalOptions”: false
}’

AND THE ERROR

HTTP 400

{
“status”: “error”,
“message”: “Unable to infer object type from: string”,
“correlationId”: “396069f9-1f6b-4262-9345-d4f884730b11”
}


@PropelYachts wrote:

Hello I’m trying to add a datetime property inside Deals but I’m getting some error

curl --request POST \
--url https://api.hubapi.com/crm/v3/properties/string \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“hidden”: false,
“displayOrder”: 2,
“description”: “Depart Time Date”,
“label”: “Depart Time Date”,
“type”: “datetime”,
“groupName”: “dealinformation”,
“name”: “departdatetime”,
“fieldType”: “date”,
“formField”: false,
“referencedObjectType”: “string”,
“calculationFormula”: “string”,
“hasUniqueValue”: false,
“externalOptions”: false
}’

AND THE ERROR

HTTP 400

{
“status”: “error”,
“message”: “Unable to infer object type from: string”,
“correlationId”: “396069f9-1f6b-4262-9345-d4f884730b11”
}


Try leaving “referencedObjectType” and “calculationFormula” empty not as “string” @PropelYachts. It worked for me

curl --request POST \
--url https://api.hubapi.com/crm/v3/properties/ \
--header ‘authorization: Bearer YOUR_ACCESS_TOKEN’ \
--header ‘content-type: application/json’ \
--data ‘{
“hidden”: false,
“displayOrder”: 2,
“description”: “Depart Time Date”,
“label”: “Depart”,
“type”: “datetime”,
“groupName”: “dealinformation”,
“name”: “departdatetime”,
“fieldType”: “date”,
“formField”: true,
“hasUniqueValue”: false,
“externalOptions”: true
}’

AND RESULT NOW IS

HTTP 404

Hey @PropelYachts I think see the issue. For objectType you have no value. It needs to be Deals in your case.