Python request returning status 400

Hello, I'm just getting to grips with the Freshdesk API. I am trying to write a query to return all tickets within a certain group that are open and am writing this :


r = requests.get("https://"+ domain +'.freshdesk.com/api/v2/tickets/?query="group_id:2043030657256%20AND%20(status:2)"', auth = (api_key, password))


but it returns status 400 when I run it, any idea where I'm going wrong? I can get other API requests working, but i'm clearly doing something wrong with the query request.


I've run into this too, and I can't figure out how to perform a query that filters tickets as you're trying to do. I noticed that the formatting of the queries is a little different depending on what you're querying in the API. For example when querying the Customer Satisfaction surveys, you don't seem to need 'query=' or double quotation marks. The below works fine:

api/v2/surveys/satisfaction_ratings?created_since=2019-03-25T00:00:00Z

I'm pretty new to this too, so I expect we're just missing something.

Update: I just spotted that the query response does in-fact tell you what the problem was. 


Mine is coming back with:

{'description': 'Validation failed',
 'errors': [{'field': 'query',
   'message': 'Unexpected/invalid field in request',
   'code': 'invalid_field'}]}

 I'm getting this response even when I copy/paste from the examples on Freshdesk's API page using standard fields, so perhaps something is amis. For example the query below (taken from the examples) gets the result above:

api/v2/tickets?query="priority:4%20OR%20priority:3"

 So for now I'm all out of ideas!

@Gabriel, I just figured it out. We are both missing /search/ in our request URL. It's that simple!


When querying for specific tickets, all tickets, applying existing filters, or applying the basic filters mentioned here it's:


/api/v2/tickets


But when querying with a URL-encoded query for things like 'priority:4', it's:


 api/v2/search/tickets


The snippet below returned the tickets between the two date ranges as expected.

api/v2/search/tickets?query="created_at:%272018-01-01%27%20AND%20created_at:%272018-02-01%27"

  

Hope that helps!

Login or Signup to post a comment