“!” is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.” error in GraphQL

“!” is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.” error in GraphQL


0

I’m trying to reach information from a GraphQL API with a Post. It’s the first time I’m working with this, and after some error I’m in a point that when the token is changed the error is ‘Unathorized’ and when I change the token the error is another one, so with that I think that the Api Url is correct. The thing is that when I’m trying to reach the json information, I have the next error:
+ InnerException {"'!' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0."} System.Exception {System.Text.Json.JsonException}
This is what I’ve done, and in the last line is when the error occurs and goes to the catch part:

            Dim httpClient As New HttpClient()
            Dim baseUrl As String = "****"
            httpClient.BaseAddress = New Uri(baseUrl)
            Dim printerId As String = "*****"
            Dim baseUrlCompleto As String = $"{baseUrl}/things/{id}"
            Dim baseUrlMedio As String = $"{baseUrl}/things"

            ' This query is taken from another place that works so it's not the problem
            Dim query As String = "
            ********
            "

            ' Define las variables de la consulta
            Dim variables As New With {
            .id = "*****"
            }

            ' Define el encabezado de autorización
            Dim authorizationHeader As String = "Bearer " & "****"

            ' Configura el cliente GraphQL
            Dim graphQLHttpClient As New GraphQLHttpClient(baseUrl, New SystemTextJsonSerializer()) 'NewtonsoftJsonSerializer())     
            graphQLHttpClient.HttpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader)
            graphQLHttpClient.HttpClient.DefaultRequestHeaders.Add("Accept", "*/*")
            graphQLHttpClient.HttpClient.DefaultRequestHeaders.Add("Host", "****")
            graphQLHttpClient.HttpClient.DefaultRequestHeaders.Add("Accept-Encoding", "*gzip, deflate, br")
            graphQLHttpClient.HttpClient.DefaultRequestHeaders.Add("Connection", "keep-alive")

            ' Crea la solicitud GraphQL
            Dim request As New GraphQLRequest With {
                .Query = query,
                .Variables = variables,
                .OperationName = "thing"
            }

            ' Realiza la solicitud GraphQL
            Dim response As GraphQLResponse(Of JObject) = graphQLHttpClient.SendQueryAsync(Of JObject)(request).Result

The code is done in vbnet, and is trying to duplicate a javascript code that works, so the query is something that works there.

I’ve also tried using NewtonsoftJsonSerializer, but the error keeps same, only with the message in another form, but is also about the invalid start with ‘!’.
I know that the error is because something that it’s not a Json is being returned, but I don’t understand why, and also I’m not able to see what’s the complete text that returns because it goes to the catch and I can’t print it to understand what it returns

Do someone know why that error occurs? Or someone that knows how to print the message it takes to give me the error (the one it has the ‘!’) and with that see what it returns and understand more

New contributor

Juan Perez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *