Answered

Error "Query body must contain a query hash" when searching conversations

  • 29 July 2023
  • 3 replies
  • 86 views

Hi, 

I’m trying to use a snippet code i got from your developer party, to search conversations between two epochs. The codes runs without a problem on your platform, but when I use it in google scripts I get the response:

{"code":"invalid_query","message":"Query body must contain a query hash"}

 

I guess it is related to the JSON payload, though the string seems to be ok.

I was able to work with the API without any problem, when I don’t send a body, but I always get the error whenever I include a body.

Any clue? 

  const str = JSON.stringify({
query: {
value: [
{field: 'created_at', operator: '>', value: '1690081199'},
{field: 'created_at', operator: '<', value: '1690167601'}
],
operator: 'AND'
}
});

const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: 'Bearer XXXXXXXXXXXXXXXXXXXXXX'
},
body: str
};

const response = UrlFetchApp.fetch('https://api.intercom.io/conversations/search', options );

 

 

 

icon

Best answer by Racheal 1 August 2023, 00:10

View original

3 replies

Userlevel 4
Badge +5

Hey @Valter Racheal from the support engineer team here👋 

 

The most common cause of this issue is missing the content-type: application/json header in the request. It does look like that header is included in the example you shared, but I'd still like to double check. It looks like your content-type may be structured different there. Can you try removing the `` around content-type and see if the results are any different?

Hi Racheal, thanks for the help. The code snipped was copied directly from my code. I tried removing the ‘’, but if I do, I can’t compile. Any other idea?

I’m attaching a screenshot of how the data is loaded into the interpreter. All looks fine.

 

I found the answer: in google script it’s “payload” not “body”

Reply