# Why does my GraphQL API Query return a 400 error in HubSpot?

**URL:** <https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [July 2, 2025, 10:15am UTC](https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547 "2025-07-02T10:15:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hkampen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hkampen/32/44643_2.png) [@hkampen](https://community.hubspot.com/u/hkampen)\
**Post date:** [July 2, 2025, 10:15am UTC](https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547/1 "2025-07-02T10:15:54Z")

</div>

Hi,

I created following query:

```lia-code-sample
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](https://api.hubapi.com/collector/v3/graphql) and [https://api.hubapi.com/collector/graphql](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

---

<div class="post-metadata">

**Author:** ![MichaelMa](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@MichaelMa](https://community.hubspot.com/u/MichaelMa)\
**Post date:** [July 2, 2025, 2:26pm UTC](https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547/2 "2025-07-02T14:26:10Z")

</div>

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:

```lia-code-sample
	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
	}

```

---

<div class="post-metadata">

**Author:** ![hkampen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hkampen/32/44643_2.png) [@hkampen](https://community.hubspot.com/u/hkampen)\
**Post date:** [July 3, 2025, 7:14am UTC](https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547/3 "2025-07-03T07:14:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [July 3, 2025, 7:42pm UTC](https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547/4 "2025-07-03T19:42:56Z")

</div>

Hey, @hkampen 👋 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

---

<div class="post-metadata">

**Author:** ![hkampen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hkampen/32/44643_2.png) [@hkampen](https://community.hubspot.com/u/hkampen)\
**Post date:** [July 4, 2025, 6:29pm UTC](https://community.hubspot.com/t/why-does-my-graphql-api-query-return-a-400-error-in-hubspot/135547/5 "2025-07-04T18:29:00Z")

</div>

Hi,

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