How do you POST a json query with a token to a web API?

Hello,
I want to post the following json code to the tibber web api. The web api expects a GraqphQL query, but there is an example on the tibber website, how to send the request in json format.
The header shall contain
Authorization: Bearer 5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE"
Content-Type: application/json
The json code for the query shall be
{ "query": "{viewer {homes {currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}" }
My code is as follows:



I get the response code 400, response type: application/json; charset=utf-8{"errors":[{"message""GraphQL operations must contain a non-empty 'query' or a 'presistedQuery' extension.","extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}
The header seems to be ok, as I don't get a authentication error.
What am I missing, so that I get this error message?

The above doesn't look like valid json ?

{"viewer": {"homes": {"currentSubscription": {"priceInfo": {"current": {"total energy tax": startsAt }}}}}}

Are you certain tibber wants the query in the format you show?

Do you have a link to their api documentation ?

[EDIT - have found the docs, and see that GQL expects a string, not formatted json]

Hmmm, just tested it, works OK for me:

Response:

{"data":{"viewer":{"homes":[{"currentSubscription":{"priceInfo":{"current":{"total":0.4078,"energy":0.2462,"tax":0.1616,"startsAt":"2024-07-27T17:00:00.000+02:00"}}}}]}}}

Blocks:

1 Like

Now it's working.
In my code I had two instructions to set the RequestHeaders.


That was the problem.
This is the correct version:

Thank you. :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.