APIs & Integrations

johnjohn123123
Participant

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

We have created a property for our compnay named "TPS Update Date" of type DatePicker as follow:-

 

TPS.png

 

but when i try to populate this property using the API i will get this error:-

 

The remote server returned an error: (400) Bad Request

 

here is a sample of the passed JSON which will raise the error:-

 

"[{\"objectId\":****,\"properties\":[{\"name\":\"email_gateway\",\"value\":\"******\"},{\"name\":\"website_gateway\",\"value\":\"****.\"},{\"name\":\"mse_scan\",\"value\":\"No\"},{\"name\":\"mse_status\",\"value\":\"****.\"},{\"name\":\"tps_update_date\",\"value\":\"1572525038454\"},{\"name\":\"tps\",\"value\":\"Allowed\"}]}]"

while if i remove the 

{\"name\":\"tps_update_date\",\"value\":\"1572525038454\"}

property from the JSON i will be able to update the record. and i am converting the date inside our c# application to unix based ..so the value i am passing will be 1572525038454 (as shown in the above json)..

 

so i am not sure why this is not working for me?

0 Upvotes
2 Accepted solutions
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Apologies for the delayed response, @johnjohn123123.

 

Thank you for sending that information along!

 

It looks like the tps_update_date property in that account has the type: "date" instead of datetime.

 

As mentioned in this article, properties with a type of date only accept UNIX millisecond timestamps at midnight UTC: "If you try to set a value that is not midnight UTC, you will receive an error."

 

In your first post, you shared the timestamp value 1572525038454, which is not at UTC midnight. If you send 1572480000000 instead, the date field should accept it.

 

Alternatively, you can change the tps_update_date property to be the type: "datetime" with this endpoint. See the example below:

 

PUT

https://api.hubapi.com/properties/v1/companies/groups/named/tps_update_date?hapikey=key

{
type: "datetime"
}

 

If  tps_update_date property is datetime, then it will accept 1572525038454.

Isaac Takushi

Associate Certification Manager

View solution in original post

johnjohn123123
Solution
Participant

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Hi Isaac,

thanks for the helpful reply. i fix this by converting the Date instead of the DateTime inside my code, and now i am able to populate the date picker value through the API.

View solution in original post

7 Replies 7
IsaacTakushi
HubSpot Employee
HubSpot Employee

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Hi, @johnjohn123123.

 

Apologies for the delayed response.

 

I do not see a company property with the internal name tps_update_date in your account with the Hub ID ending in 0966. Am I looking in the correct account or did you delete the property?

 

Also, could you share a request URL you were testing with? (For example: https://api.hubapi.com/companies/v2/companies/1234567.) Please remove any hapikey values.

Isaac Takushi

Associate Certification Manager
johnjohn123123
Participant

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Thanks for the reply. i am developing an console application for 3rd party compnay.. so do you need their ID? and can i send it in a confidentail way?

 

here is the c# code to intigrate with the API:-

 

using (WebClient wc = new WebClient())
         {
               string url = "https://api.hubapi.com/companies/v1/batch-async/update?hapikey=******";
               Uri uri = new Uri(url);
               wc.Encoding = System.Text.Encoding.UTF8;
               wc.Headers.Add(HttpRequestHeader.ContentType, "application/json");
               var apiupdateresults = wc.UploadString(uri, data);
               Console.WriteLine("Api update results= " + apiupdateresults);
         }

 

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Sure, could you direct message it to me? Also, do you have an object ID you've been testing with that I could also use?

Isaac Takushi

Associate Certification Manager
0 Upvotes
johnjohn123123
Participant

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Hi @IsaacTakushi , did you have the chance to check the above ?

 

Thanks

0 Upvotes
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Apologies for the delayed response, @johnjohn123123.

 

Thank you for sending that information along!

 

It looks like the tps_update_date property in that account has the type: "date" instead of datetime.

 

As mentioned in this article, properties with a type of date only accept UNIX millisecond timestamps at midnight UTC: "If you try to set a value that is not midnight UTC, you will receive an error."

 

In your first post, you shared the timestamp value 1572525038454, which is not at UTC midnight. If you send 1572480000000 instead, the date field should accept it.

 

Alternatively, you can change the tps_update_date property to be the type: "datetime" with this endpoint. See the example below:

 

PUT

https://api.hubapi.com/properties/v1/companies/groups/named/tps_update_date?hapikey=key

{
type: "datetime"
}

 

If  tps_update_date property is datetime, then it will accept 1572525038454.

Isaac Takushi

Associate Certification Manager
johnjohn123123
Solution
Participant

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Hi Isaac,

thanks for the helpful reply. i fix this by converting the Date instead of the DateTime inside my code, and now i am able to populate the date picker value through the API.

johnjohn123123
Participant

Unable to populate Date picker value using the API "Error Bad request"

SOLVE

Hi @IsaacTakushi 

 

I just send you a message with all the info you asked for.

 

Thanks for your help

 

0 Upvotes