Skip to main content

Hi,

I had opened a ticket which was flagged as solved, but it’s not solved. 

 

I’m trying to use a snippet code i got from your developer website, 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.

I do have the ‘application/json’ in the code (the snipped below was copied directly) and I’ve tested removing the apostrophes from ‘content-type’ and I still get the same error.

I’m adding a screenshot of the data structure in my memory. All looks as it should.

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

 

 

Hi @Valter !

The only suggestion I have here is to put your key values (query, field, etc) in quotes. I know when I run the command in Postman I hit a snag if I don’t use quotes around those. That said, it looks like it’s automatically adding those quotes in the screenshot. However, it’s also putting quotes around the entire query object. Not sure if that would be causing an issue or not, but might be something to look into.

Have you tried running this in a different tool such as Postman to see if there’s anything you can learn from trying a different setup?

It would seem this has to do with a translation issue around how to make that call using Google Scripts. It would seem when you’re passing in the ‘str’ value into the ‘body’ it’s not reading it as intended. You may want to dig into how Google wants that formatted to confirm it’s using their specifications.


Thanks Jacob. I had ran the code in intercom’s documentation page (I copied it from there). I was hoping there was an obvious reason for it not to work, that I was not seeing, or that someone had encountered the same problem.

 

I indeed tried as you suggested. I tried everything with and without quotes, but I was no luckier. I’ve also read through google documentation, but they suggest to go just as I did above. I was hoping there was something on Intercom’s API preventing the call from working.

Anyway, I’ll continue digging. Thanks for the help


Hi @Valter!  What you have to do is modify "body" to "payload". I know this because I was working on an integration with AppScripts, I hope you have solved it.


Reply