Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Struggling with Graphql syntax

Solved

Struggling with Graphql syntax

dhts
Shopify Partner
2 1 0

I'm trying to write some vb.net code to call Graphql using httpclient (the postasync call).

 

This example works:

Dim body As String = "{""query"": ""{shop {name} }""}"

as does:

Dim body As String = "{""query"": ""{products(first: 3) {edges {node {id title} } } }""}"

but I'm struggling with the syntax for extending the set of products return to those which match a product_type, so this:

Dim body As String = "{""query"": ""{products(first: 3, query:""product_type:Fabric"") {edges {node {id title} } } }""}"

returns "Bad Request"

 

the string is being encoded as:

 Dim content = New StringContent(body, Encoding.UTF8, "application/json")

and called as:

Dim response = request.PostAsync(url, content).Result

 

Any pointers most welcome.

Accepted Solution (1)

dhts
Shopify Partner
2 1 0

This is an accepted solution.

I eventually worked it out and posting here in case it helps someone in the future. The answer was to escape the double quotes in the middle query so this works:

Dim body As String = "{""query"": ""{products(first: 3, query:\""product_type:Fabric\"") {edges {node {id title} } } }""}"

View solution in original post

Replies 3 (3)

Eric-HAN
Shopify Partner
273 30 29

Dim body As String = "{""query"": ""{products(first: 3, query:""product_type:Fabric"") {edges {node {id title} } } }""}"   this word in red also shoud be quoted 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Eric-HAN
Shopify Partner
273 30 29

please ignore the reply. It is not right

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee

dhts
Shopify Partner
2 1 0

This is an accepted solution.

I eventually worked it out and posting here in case it helps someone in the future. The answer was to escape the double quotes in the middle query so this works:

Dim body As String = "{""query"": ""{products(first: 3, query:\""product_type:Fabric\"") {edges {node {id title} } } }""}"