Hello!
I am new to GraphQL and I try to make an API request. I know the query string should be correct because there is a playground here where it is possible to paste this query string:
query { pools (where: {id: "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8"}){ tick sqrtPrice liquidity feeTier token0 { symbol decimals } token1 { symbol decimals}}}
Which works on this url in the Playground box:
https://thegraph.com/legacy-explorer/subgraph/uniswap/uniswap-v3
However when I try to make this API query call. I get the exception: System.Net.WebException: 'The remote server returned an error: (400) Bad Request.'
I can't figure out why I get this error.
- I have tried all those ContentTypes:
application/json --- application/x-www-form-urlencoded --- application/graphql
- I have tried with and without the line:
request.Headers.Add("Authorization", ApiKey);
Thank you!
void testGraphQL_ApiCall()
{
String query = "query { pools (where: {id: " + '"' + "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8" + '"' + "}){ tick sqrtPrice liquidity feeTier token0 { symbol decimals } token1 { symbol decimals}}}";
String ApiKey = "myapikey";
String ApiUrl = "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3";
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(ApiUrl);
var data = Encoding.ASCII.GetBytes(query);
request.Method = "POST";
request.ContentType = "application/graphql"; //application/json application/x-www-form-urlencoded application/graphql
request.ContentLength = data.Length;
request.Headers.Add("Authorization", ApiKey); //I have tried with and without this
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (System.Net.HttpWebResponse)request.GetResponse();
String responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
MessageBox.Show(responseString);
}