# GraphQL from Serverless Issue

**URL:** <https://community.hubspot.com/t/graphql-from-serverless-issue/56451>\
**Category:** APIs & Integrations\
**Created:** [May 7, 2022, 5:22pm UTC](https://community.hubspot.com/t/graphql-from-serverless-issue/56451 "2022-05-07T17:22:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [May 7, 2022, 5:22pm UTC](https://community.hubspot.com/t/graphql-from-serverless-issue/56451/1 "2022-05-07T17:22:55Z")

</div>

Hey Community,

I’m attempting to hit the GQL endpoint from serverless function. When requested I get the response:

```lia-code-sample
{
 "response": {
 "statObjs": {
 "message": "Request failed with status code 400",
 "name": "Error",
 "stack": "Error: Request failed with status code 400\n at createError (/opt/nodejs/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/opt/nodejs/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/opt/nodejs/node_modules/axios/lib/adapters/http.js:236:11)\n at IncomingMessage.emit (events.js:326:22)\n at endReadableNT (_stream_readable.js:1241:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)",
 "config": {
 "url": "https://api.hubapi.com/collector/graphql?hapikey=XXXXXXXXXXXXXXXXX",
 "method": "post",
 "data": "{\"header\":{\"Content-Type\":\"application/json\",\"Accept\":\"application/json, text/plain, */*\"},\"body\":\"\\\"{\\\\n \\\\\\\"operationName\\\\\\\": \\\\\\\"myquery\\\\\\\",\\\\n \\\\\\\"query\\\\\\\": \\\\\\\"query myquery($contactid: String!,$id: String!,$reporttype: String!) { CRM {contact(uniqueIdentifier: $id, uniqueIdentifierValue:$contactid) { name associations { p_repoted_stat_collection__reported_stat_to_contact(limit: 200, filter: {recordtypename__eq: $reporttype}) {total items {report_week}} } }}}\\\\\\\",\\\\n \\\\\\\"variables\\\\\\\": {\\\\\\\"contactid\\\\\\\": \\\\\\\"1398551\\\\\\\", \\\\\\\"id\\\\\\\": \\\\\\\"id\\\\\\\", \\\\\\\"reporttype\\\\\\\": \\\\\\\"weekly\\\\\\\"}\\\\n }\\\"\"}",
 "headers": {
 "Accept": "application/json, text/plain, */*",
 "Content-Type": "application/json;charset=utf-8",
 "User-Agent": "axios/0.19.2",
 "Content-Length": 631
 },
 "transformRequest": [
 null
 ],
 "transformResponse": [
 null
 ],
 "timeout": 0,
 "xsrfCookieName": "XSRF-TOKEN",
 "xsrfHeaderName": "X-XSRF-TOKEN",
 "maxContentLength": -1
 }
 }
 }
}

```

The Integrations Call Log:

```lia-code-sample
{
 "status": "error",
 "message": "Invalid input JSON on line 1, column 631: Cannot build GraphQLQuery, some of required attributes are not set [query]",
 "correlationId": "XXXXXXXXXX"
}

```

The query:

```lia-code-sample
{
 "operationName": "myquery",
 "query": "query myquery($contactid: String!,$id: String!,$reporttype: String!) { CRM {contact(uniqueIdentifier: $id, uniqueIdentifierValue:$contactid) { name associations { p_repoted_stat_collection__reported_stat_to_contact(limit: 200, filter: {recordtypename__eq: $reporttype}) {total items {report_week}} } }}}",
 "variables": {"contactid": "1398551", "id": "id", "reporttype": "weekly"}
 }

```

When using this query with postman I do get the expected results.

I can’t quite figure out whats causing the query not to be set?

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [May 7, 2022, 5:47pm UTC](https://community.hubspot.com/t/graphql-from-serverless-issue/56451/2 "2022-05-07T17:47:18Z")

</div>

I think I might be passing the payload in incorrectly? But thats just an assumption based on the response not find the query.

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [May 9, 2022, 7:45am UTC](https://community.hubspot.com/t/graphql-from-serverless-issue/56451/3 "2022-05-09T07:45:14Z")

</div>

Hi @Kevin-C  
Is the error caused because HubSpot can not find the query? Or is it caused because the query contains a param that is not passed correctly?

If it is the first, just to have the code identical to the docs, could you add a space after ‘myquery’:

```lia-code-sample
{
 "operationName": "myquery",
 "query": "query myquery ($contactid: String!,$id: String!,$reporttype: String!) { CRM {contact(uniqueIdentifier: $id, uniqueIdentifierValue:$contactid) { name associations { p_repoted_stat_collection__reported_stat_to_contact(limit: 200, filter: {recordtypename__eq: $reporttype}) {total items {report_week}} } }}}",
 "variables": {"contactid": "1398551", "id": "id", "reporttype": "weekly"}
 }

```

If it is the second, could you try, for the sake of testing, to only use non-required params for your query? So use **String** instead of **String!**  
I do not see anything wrong with your code.

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [May 14, 2022, 1:14pm UTC](https://community.hubspot.com/t/graphql-from-serverless-issue/56451/4 "2022-05-14T13:14:46Z")

</div>

Thank you @Teun !
