Need a special offer?Find out if your project fits.
+

How to handle ISO8601 date string using Custom API

Answered
Mark Spicer asked on July 2, 2020

I am creating a custom API and not sure how to handle dates. My API fetches the data from the database and returns them as ISO8601 text strings (yyyy-mm-dd - e.g. 2020-07-02). I have my report specified as below:


"report":{
"dataSource":{
"type":"api",
"url":"http://localhost:3000/cube",
"index":"someindex",
"mapping":{
"reporting_date":{
"caption":"My Reporting Date",
"type":"date string"
}
}
},
"options":{
"grid":{
"type":"flat"
},
"datePattern":"yyyy-MM-dd"
}
}

When I want to use the dates in Flexmonster I'm getting errors with both the flat and compact and classic display options. With the 'flat' option I see the grid but all of the dates show "Invalid date". When I use the compact or classic option, the grid doesn't display but I get an error message dialog "Error: Cannot read property 'ordinal' of null".
I have tried various different approaches with various mapping types but I can't seem to find the solution. I tried changing the mapping type to "date" and then it creates 3 separate fields - for "My Reporting Date.Day" as well as .Month & .Year - and I don't have those fields obviously.
I just needs some advice on how I should be handling ISO8601 dates please.

3 answers

Public
Vera Didenko Vera Didenko Flexmonster July 2, 2020

Hello, Mark,
 
Thank you for reaching out to us. 
 
We would like to kindly explain that for the custom data source API, dates should be passed in the form of a Unix timestamp.
For example, "2016-02-07" needs to be fed into Flexmonster as "1454803200000". Then the dates should be recognized correctly and the datePattern property can be applied.
 
Please let us know if this helps. 
Looking forward to your reply. 
 
Kind regards, 
Vera

Public
Mark Spicer July 2, 2020

Hello Vera
Ah, OK, thank you very much, at least that explains my problem. I didn't try that, although, as I have experience of Elasticsearch I maybe should have thought of that.
But I want you to know that this has given me a brainwave! I may be able to use Elasticsearch instead of creating my own API, this may make some things easier for me, but other a little more complex, but I thank you for giving me the idea.
And thank you for your excellent support.
Regards
Mark
 

Public
Vera Didenko Vera Didenko Flexmonster July 6, 2020

Hello, Mark, 
 
Thank you for your feedback. 
 
We are glad to hear that you found the explanation helpful. 
Our team will review the corresponding documentation and see how it can be improved to make the integration process simpler.
 
As always, please feel free to reach out to us if further questions arise.
 
Kind regards, 
Vera

Please login or Register to Submit Answer