APIs & Integrations

Kevin-C
Experto reconocido | Partner
Experto reconocido | Partner

GraphQL from Serverless Issue

resolver

Hey Community,

 

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

{
    "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:

{
  "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:

{
        "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?

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Me gusta
1 Soluciones aceptada
Teun
Solución
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

GraphQL from Serverless Issue

resolver

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':

{
        "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.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Ver la solución en mensaje original publicado

3 Respuestas 3
Kevin-C
Experto reconocido | Partner
Experto reconocido | Partner

GraphQL from Serverless Issue

resolver

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

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Me gusta
Teun
Solución
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

GraphQL from Serverless Issue

resolver

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':

{
        "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.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Kevin-C
Experto reconocido | Partner
Experto reconocido | Partner

GraphQL from Serverless Issue

resolver

Thank you @Teun !

Kevin Cornett - Sr. Solutions Architect @ BridgeRev