Hello all,


I have the following requirement which I need some help with.

I am consuming a Rest API and Advanced section Date format is set to 2014-01-01T00:00:00Z (ISO) like this: 


For all get methods from this API Dates come like "/Date(1590537600000)/". The fields that return dates in this format are mapped as Date Time in Service Studio. This works perfectly and by default dates end up with format "2020-06-12 17:59:47" so I can directly work with the values.


However the issue comes with the POST methods which require date fields to be in format "/Date(1590537600000)/". Whenever I pass the OutSystems dates to the JSON file they always end up with format "2020-06-12 17:59:47" and the API returns a 400 Bad Request.


My question is: How can I convert this "2020-06-12 17:59:47" OutSystems date into this format: "/Date(1590537600000)/"



Thank you all

Hi,

What you could try is in your post request use data type string for this datetime attribute.

Create a server action with is function property set to True with input parameter of DateTime and an output parameterof type string.

Add logic to it to convert the datetype.

Then on the POST call pass the result of the conversion on the api method parameter.

Regards,

Daniel


Daniël Kuhlmann wrote:

Hi,

What you could try is in your post request use data type string for this datetime attribute.

Create a server action with is function property set to True with input parameter of DateTime and an output parameterof type string.

Add logic to it to convert the datetype.

Then on the POST call pass the result of the conversion on the api method parameter.

Regards,

Daniel


Hello and thanks for the reply.


Actually what I really don't know how to do is this:

"Add logic to it to convert the datetype"


What logic for conversion is this? Any out of the box Function or do I need an extension like "Epoch Date Time"?


Thanks



Solution

Hi Pedro,

Did you set the date format property of the REST API to WCF? 

Regards,

Daniel

Solution

Daniël Kuhlmann wrote:

Hi Pedro,

Did you set the date format property of the REST API to WCF? 

Regards,

Daniel

That did the trick! Thank you. I was affraid that would affect the inflow Data, but it seems to only affect the outflowing data.

I set date format to WCF and map all fields to Date Time. Worked a charm.


Thanks