How to configure a timezone in stateExtension of HTTP Binding

I use the HTTP binding to call an API with the following URL:

/v1/statistics/gateways/<anyId>?accuracy=high&from=%1$tY-%1$tm-%1$tdT00:00:00.000Z&to=%1$tY-%1$tm-%1$tdT23:59:59.000Z

With the parameters “from” and “to” I limit a time range. In my concrete case I want to use today’s day from 00:00 to 24:00.

So far so good, the example above works, but the timezone is not correct because with the ‘Z’ I use UTC. In fact I want to use “CET” and “CEST” instead of ‘Z’. But when I just write “CEST” instead of ‘Z’, then I get a “400 Bad Request”.

How do I have to configure the “stateExtension” in the HTTP binding to query the current day considering the timezone?

If the API is compliant with ISO 8601: use +02:00 instead of CEST.

Thanks for your reply. That is somthing I had alredy tried before…

The API requires an iso date. When I try your suggestion in the API’s swagger ui, then I can send successful requests with an “+02:00” offset as mentioned by you (see screenshot):

When I do the same with the HTTP Binding, then I receive the following Error in the logfile:

Requesting 'https://cloud.solar-manager.ch/v1/statistics/gateways/<anyId>?accuracy=high&from=2023-02-15T00:00:00.000+02:00&to=2023-02-15T23:59:59.000+02:00' (method='GET', content='null') failed: 400 Bad Request

When url encoding the ‘+’ and ‘:’ character I receive the following error:

Creating request for 'https://cloud.solar-manager.ch/v1/statistics/gateways/<anyId>?accuracy=high&from=%1$tY-%1$tm-%1$tdT00:00:00.000%2B02%3A00&to=%1$tY-%1$tm-%1$tdT23:59:59.000%2B02%3A00' failed: Format specifier '%3A'

After studying the error message from my last post again in detail, I have now found the solution by myself:

The URL must be encoded as follows, and then additionally the option “escaped url” must be activated in the HTTP binding:

/v1/statistics/gateways/?accuracy=high&from=%1$tY-%1$tm-%1$tdT00:00:00.000 %%2B 01 %%3A 00&to=%1$tY-%1$tm-%1$tdT23:59:59.000 %%2B 01 %%3A 00

2 Likes