Padma
Padma

Reputation: 1

Send graphql to the Post body in Restsharp automation

throwing the below error when I pass GraphQL to the AddParameter#

{"errors":[{"message":"Expected \u0060{\u0060 or \u0060[\u0060 as first syntax token.","locations":[{"line":1,"column":1}],"extensions":{"code":"EXEC_SYNTAX_ERROR"}}]}

RestClient restClient = new RestClient("https://xxxxxx"); 

var request = new RestRequest(Method.POST);   

request.AddHeader("Authorization", "Bearer " + AccessToken);

request.AddHeader("Content-Type", "application/json");           

request.AddParameter("application/graphql","{\"query\":\"{\\n agreements(where : submissionId:\\\"180823\\\") }" + ParameterType.RequestBody);

var resp = restClient.Execute(request);

Upvotes: 0

Views: 1578

Answers (1)

Jonas Jerndin
Jonas Jerndin

Reputation: 166

I had similar issue when using HttpClient. Solved by UTF8 encode the query.

        var gql = @"{""query"": ""{something { field1, field2 } }""}";

        var message = new HttpRequestMessage(HttpMethod.Post, "https://xxxxxx/graphql")
        {
            Headers =
            {
                {"Authorization", token}
            },
            Content = new ByteArrayContent(Encoding.UTF8.GetBytes(gql))
            {
                Headers =
                {
                    {"Content-Type", "application/json"}
                }
            }
        };

Upvotes: 0

Related Questions