GraphQL HTTP POST-Request Error; "Problems parsing JSON"

 Hello, I am having some trouble parsing JSON  data in the  GitHub GraphQL API. I am unsure if I am not writing the JSON in the correct format, or there’s another problem stemming from it. Below are photos of my command-prompt and my Visual Studio Code window: 

 I appreciate any help that I can get for this error; have been very busy recently and am now able to write a post about this ongoing issue. Thanks!

It looks like you forgot the word query from the first line of your GraphQL query structure, before the opening curly brace. This is understandable because there’s a lot of use of the word query in your code example :grinning: So the contents should probably be:

query { repository(owner: ...

I hope that helps!

1 Like

I have tried adding query like your example shows but that method still results in the same parsing error. Any other ideas? Thanks!

Have you tried putting the query into the Explorer tool in our developer site to see what error message it shows?

1 Like

Yep, tried the Explorer before writing the code just to make sure the query worked properly. Not sure what could be causing this error to occur.

Ok, so then it isn’t the query text itself but the method of calling the endpoint that is the problem. The only guess I have there is that you seem to be using the JavaScript request library and the documentation seems to indicate that the form parameter of the post method adds the data you supply as querystring parameters, rather than adding the text to the body. Try supplying the query contents to the body parameter of the post method instead.

1 Like

Thank you, this  did fix my problem. Alongside that, I also made sure to set the json parameter to true within the statement!

1 Like