How to send INT variable in HTTP request body

Hi everyone! I’m working with HTTP Request i need to do POST into my API.
I need to send some information in INT format. My API requires it.
Syntax in this case is:

““start_date””: “”"+startDate+"""

HTTP Request, want to automaticly convert it to string.
Can i send it as INT32?

@Kamil_Cyrek

Body part will accept string only but not Integer. Then why you want to convert it to Interger ?

1 Like

You say your API requires the date information as an INT (Integer?).

How does that work? Usually dates would be required as DateTimes or Strings in a specific format.

1 Like

It’s a timestamp

My API expected INT type in this in this field :confused:
If i send it, in string. API return: ERR 400, bad request.

As I said, DateTimes or timestamps are not usually given as Integers. I guess your API is parsing it somehow? What is the date format required?

I gave timestamps to an API before, but as a string and had it formatted like this:

""date_from"": ""2019-11-01T22:00:00.000Z""

1 Like

Unfortunately :confused:
image

Well, you have to find out in which format your API wants this information. It could be yyyyMMdd like this:

""date_from"": 20191101

It could include the time somehow also, maybe yyyyMMddhhmmss

2 Likes

Ok, thanks. I have one more simple question with this problem.
I can send it as

““start_date””: 1584352800000

. And it’s works.
But i can’t do

““start_date””: “”"+startDate+"""

but in startDate is 1584352800000 - the same value.

It’s weird because your API accepts only Integer, but RequestBodies usually get sent as string.

Given you startDate variable is of variable type integer, here is what you got to do:

" ""start_date"":" + startDate.ToString

2 Likes

Thanks, but this syntax doesn’t work.
End of statement expected.

When i tryed:

““start_date””: “”"+startDate+"""

I can’t convert from double to string.

Since you are sending the RequestBody as String anyways, may I suggest you keep the startDate as String or DateTime? Why are you keeping it as double? Here is an example for DateTime:

SampleDate (DateTime) = Today
" ""start_date"":" + sampleDate.ToString(yyyyMMdd)

2 Likes

Usually when date type needs to go as number you use like this:

Dim dt = Date.Parse("22.03.2020 07:07:32") 
Dim ticks As Long = dt.Ticks

The think is that integer would be too small to represent a date…

1 Like