Skip to main content
Answered

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


  • New Participant
  • 3 replies

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 );

 

 

 

Best answer by Racheal

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?

View original
Did this topic help you find an answer to your question?

3 replies

Racheal
Intercom Team
Forum|alt.badge.img+5
  • Customer Support Engineer
  • 512 replies
  • Answer
  • July 31, 2023

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?


  • Author
  • New Participant
  • 3 replies
  • July 31, 2023

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.

 


  • Author
  • New Participant
  • 3 replies
  • August 13, 2023

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings