Solved

REST API: Dynamic Dates, inputs and Data Selection Rules

  • 26 January 2022
  • 8 replies
  • 157 views

Hi

This is a somewhat similar question asked by Sturla Svendsen

The API I am using only returns data when fromDate and toDate are populated in the URL params.

When setting up the Data Source (CData) I won't be able to fetch anything without these dates.

I have tried creating the datasource with hard coded dates in the Edit-window in DH and altering the RSD-file the way that Thomas Lind informed Sturla about in the post linked above.

However, when I delete the URL params in the Edit-window, and rely solely on the already created RSD-file, the connection won't work (401 as the url is invalid).

When I try to add data selction rules and execute, it states the the input fields (that are written in the api:info-secion of the RSD-file) are unknown.

I really could use an complete answer as to how to connect to an API with dynamic dates in the URL params.

The guides/documentation found on this webpage is fragmented and doesn't work with the use case above.

Thank you

 

Kenneth

icon

Best answer by Thomas Lind 27 January 2022, 11:39

View original

8 replies

Userlevel 6
Badge +5

Hi Kenneth

I have since updated my RSD guide with some info about how I add a dynamic date to a RSD file.

https://legacysupport.timextender.com/hc/en-us/articles/360052383191-Creating-and-using-RSD-files-for-CData-providers#h_01F4S5NBJ6ENMBF7JA4MMMNEAM

I would start by generating the rsd with some mock dates I know will give a successful test connection. Then add the changes to that while keeping the dates as default values.

Hi Kenneth

I have since updated my RSD guide with some info about how I add a dynamic date to a RSD file.

https://legacysupport.timextender.com/hc/en-us/articles/360052383191-Creating-and-using-RSD-files-for-CData-providers#h_01F4S5NBJ6ENMBF7JA4MMMNEAM

I would start by generating the rsd with some mock dates I know will give a successful test connection. Then add the changes to that while keeping the dates as default values.

 

Hi Thomas,

I’ve managed to setup the RSD-file, however I need to make it dynamic.

I need to dynamically calculated the current UTC datetime to parse to a custom header.

 

  <api:set attr="Header:Name#"  value="utcdate" />
  <api:set attr="Header:Value#" value="2024-05-31 09:33:00" />

 

The bold part needs to be dynamically calculated. Do you have an idea how to approach that?

I couldn’t make it work using the available guide.

Userlevel 6
Badge +5

Hi @Erwins 

Is the date applied set up as yyyy-mm-dd HH:mm:ss or similar?

Does it work if you manually apply a date like you do in the example?

I have seen some dates having to use the following yyyy-MM-dd'T'HH:mm:ss.SSSz or similar.

Hi @Thomas Lind ,

 

the date needs to be exactly as in my example. So there probably needs to be some formatting applied also when the datetime is generated dynamically. It’s also important the datetime is converted to UTC first.

 

the RSD file works with my example.

Userlevel 6
Badge +5

Hi @Erwins 

You could try this function instead of date.

[attr | utcnow([outputformat])]

Returns the current system UTC date and time.

  • outputformat: The optional format specifier. Valid specifiers include d (short date pattern), D (long date pattern), f (long date/short time pattern), F (long date/time pattern), g(general short date/time pattern), G (general short date/long time pattern), r or R (RFC1123 pattern), s (sortable date/time pattern), t (short time pattern), T (long time pattern), file (Windows file time), MM/dd/yy, etc.

 

So set up the value as utcnow()

Like 

<api:set attr="Header:Name#"  value="utcdate" />
<api:set attr="Header:Value#" value="[utcnow()]" />

 

Hi @Thomas Lind ,

This:

  <api:set attr="Header:Name#"  value="utcdate" />
<api:set attr="Header:Value#" value="[utcnow()]" />

 

Gave me this result:

 

Userlevel 6
Badge +5

Hi @Erwins 

I thought it would work without adding an outputformat. Try to add it with an upper case F like so.

<api:set attr="Header:Name#"  value="utcdate" />
<api:set attr="Header:Value#" value="[utcnow('F')]" />

F should be equal to long date/time pattern

Otherwise try with ‘yyyy-MM-dd HH:mm:ss’

Hi @Thomas Lind,

 

Adding the ‘F’ returns:

 

Reply