Error 400 with GraphQL

Hi,

I created following query:

query example_1 {
 CRM {
 contact_collection (limit: 10) {
 items {
 hs_object_id firstname lastname email
 associations {company_collection__primary {items {hs_object_id name domain country}}
 }
 }
 }
 }
}

The JSON request contains “query”: …, “variables”: null, “operationName”: “example_1”

I tested https://api.hubapi.com/collector/v3/graphql and https://api.hubapi.com/collector/graphql as endpoint, auth with authorization Bearer token.

I copied the query into the GraphQL tool in my account and it works. The payload there is identical with my payload, but I get following error:

HubspotResponseException: 400: {"status":"error","message":"Invalid input JSON on line 1, column 1: Cannot construct instance of com.hubspot.bootstrap.graphql.GraphQLQuery$Json (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('query example_1 {\n CRM {\n contact_collection (limit: 10) {\n items {\n hs_object_id firstname lastname email\n associations {company_collection__primary {items {hs_object_id name domain country}}\n }\n }\n }\n }\n}')","correlationId":"cd45578a-c75f-450f-9879-fcc35c86b0a2"}

What is wrong?

Regards
Harald

Not sure if it’s applicable in your case but one thing I found when I was creating CRM cards and using GraphQL was that the payload request did not like new lines or tabs in the query. It would fail every time. I had the same issue of “this works everywhere else but not in the one specific instance despite everything being the same!”.

I ended up converting the query into a single-line string in my code and then it worked fine. I see the \n (newline) in the query in the error although not sure sure if that is because of the error response breaking up the lines for you or if it’s the query being sent in. But you might try making the query a single string and see if that works for you.

For reference (since you didn’t post your code), my code for setting up the payload:

	const payload = {
		"operationName": "getData",
		"query": "query getData($hs_pipeline: HS_Pipeline_Enum!, $hs_pipeline_stage: HS_Pipeline_Stage_Enum!) { CRM { p_inventories_collection( filter: {hs_pipeline__eq: $hs_pipeline, hs_pipeline_stage__eq: $hs_pipeline_stage} limit: 150 orderBy: opportunity__asc ) { items { "+fields.join(" ")+" } } } }",
		"variables": data
	}

Hi MichaelMa,

that doesn’t change the error. It seems to me that the Java parser tries to parse the query as JSON.

Regards

Harald

Hey, @hkampen :waving_hand: You are correct in your follow-up.

To help us figure out exactly why that’s happening, would you be able to share a code snippet showing how you are building and sending the request? Seeing the actual implementation allows our community experts and champions to spot the issue quickly. — Jaycee

Hi,

it was my fault. I have only sent the graphql query, not the JSON. But thanks for help!