tibber / Tibber.SDK.NET

Tibber C# SDK.NET
MIT License
35 stars 5 forks source link

PriceInfoQueryBuilder.WithRange() causes cursor error #8

Closed swaglordmcmuffin closed 1 year ago

swaglordmcmuffin commented 1 year ago

I might have misunderstood something here, but the SubscriptionPriceConnectionQueryBuilder.WithRange() fails to convert the date to the required BASE64 string.

By submitting the required DateTimeOffset object the Tibber API responds with error "\"after\" must be a valid cursor instance".

Example code:

var basicData = await _client.GetBasicData();
            var homeId = basicData.Data.Viewer.Homes.First().Id.Value;

            DateTimeOffset afterDate = new DateTime(2023,01,01,0,0,0);

            var customQueryBuilder =
                new TibberQueryBuilder()
                .WithViewer(
                    new ViewerQueryBuilder()
                        .WithHome(
                            new HomeQueryBuilder()
                                .WithCurrentSubscription(
                                    new SubscriptionQueryBuilder()
                                        .WithPriceInfo(
                                            new PriceInfoQueryBuilder()
                                                .WithRange(
                                                    new SubscriptionPriceConnectionQueryBuilder()
                                                        .WithNodes(
                                                            new PriceQueryBuilder()
                                                                .WithAllFields()
                                                        ),
                                                    resolution: PriceResolution.Hourly,
                                                    after: afterDate,
                                                    last: 1000
                                                )
                                        )
                                ),
                            homeId
                        )
                );

            try
            {
                var query = customQueryBuilder.Build();
                var response = await _client.Query(query);

From what I can see when viewing the query variable above the date is a plain string instead of the BASE64 conversion:

"query{viewer{home(id:\"xxxx-xxxx-xxxx-xxxx\"){currentSubscription{priceInfo{range(resolution:HOURLY,last:1000,after:\"2023-01-01T00:00:00.0000000+01:00\"){nodes{total,energy,tax,startsAt,currency,level}}}}}}}"

Am I missing something here or is this an error in the Tibber SDK?

Best regards, Linus

toini commented 1 year ago

@swaglordmcmuffin looks like you came up with a solution?

swaglordmcmuffin commented 1 year ago

@toini Hi, yes. I did something with something, and all of a sudden I got it to work. I just need to figure out the root cause and potential solution and I'll update this with any finding.

I closed it to prevent you from unecessary debugging in the meantime :)