APIs & Integrations

HOrdonez
Participant

Filter API Request by timestamp

Dear all,

 

I would like to ask if there is any way to add a timestamp (or date) in order to filter the results for an API request.

 

What I have beeen doing for now is getting all the data and filter by myself later on, but this solution is not scalable and I don't want to collapse the API limit.

 

For example, if I want to get feedback submissions (in python), right now I'm doing:

client.crm.objects.feedback_submissions.basic_api.get_page()

Is there any way to add a time range, a `from` or a `to` in the request?

 

I would like to ask if there is any way to get the list of properties that I can add to the request.

 

Thank you in advance.

0 Votes
10 Réponses
HOrdonez
Participant

Filter API Request by timestamp

Hi @dennisedson , any update?

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Filter API Request by timestamp

@HOrdonez , make sure you are using milliseconds for the unix timestamp.

I tested with this request successfully:

{
  "filterGroups": [
    {
      "filters": [
        {
          "value": "1635032689886",
          "propertyName": "hs_lastmodifieddate",
          "operator": "GT"
        }
      ]
    }
  ]
}
HOrdonez
Participant

Filter API Request by timestamp

@dennisedson thank you for your answer, it worked.

I would like to ask if it's possible to get the properties of Feedback from some API. 

Even Feedback is an Object type in Hubspot. This doesn't work.

 

client.crm.properties.core_api.get_all(object_type='FEEDBACK',
archived=False)

 

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Filter API Request by timestamp

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Filter API Request by timestamp

@HOrdonez ,

You should explore the search endpoints.  You can use a filter group with a from and to range

HOrdonez
Participant

Filter API Request by timestamp

Thank you for your answer @dennisedson . I cannot find which Object Type is associated with feedback_submissions or if it's available the search option for it.

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Filter API Request by timestamp

@HOrdonez 

Feedback submissions is an Object. 

You can see details on the endpoints, including search here

0 Votes
HOrdonez
Participant

Filter API Request by timestamp

Thank you @dennisedson. I see that Feedback Submission has a search endpoint in the documentation that you sent, but is not in the other one.

 

The Python proposed implementation is not updated.

 

This is the one you provide:

client.crm.feedback_submissions.search_api.do_search(
public_object_search_request=public_object_search_request)

This is the one I think it should be:

 

client.crm.objects.feedback_submissions.search_api.do_search(
public_object_search_request=public_object_search_request)

I would like to ask as well, if I want to filter the feedback submitted after yesterday using `hs_lastmodifieddate`, I declare the following object:

 

public_object_search_request = 
PublicObjectSearchRequest(filter_groups=[{"filters":[{"value":"2021-10-27",
"propertyName":"hs_lastmodifieddate","operator":"GT"}]}],
properties=["hs_lastmodifieddate"], limit=0, after=0)

But I'm getting that exception, so I may be doing something wrong:

 

hubspot.crm.objects.feedback_submissions.exceptions.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 28 Oct 2021 13:14:26 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '123', 'Connection': 'keep-alive', 'CF-Ray': 'X', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Vary': 'Accept-Encoding', 'CF-Cache-Status': 'DYNAMIC', 'Access-Control-Allow-Credentials': 'false', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'X-HubSpot-Correlation-Id': 'X', 'X-HubSpot-RateLimit-Daily': '500000', 'X-HubSpot-RateLimit-Daily-Remaining': 'X', 'X-Trace': 'X', 'Report-To': '{"endpoints":[{"url":"x"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare', 'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400'})
HTTP response body: {"status":"error","message":"There was a problem with the request.","correlationId":"x"}

 

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Filter API Request by timestamp

@HOrdonez .

I will check with the team on why this object is not in the search documentation.

Why do you think that implementation is incorrect.  It appears consistent with the other objects' python examples.

 

As for the error, try using a unix timestamp  as your value.

0 Votes
HOrdonez
Participant

Filter API Request by timestamp

@dennisedson  The CRM Discovery object has not feedback_submission property, this one is inside object as I mentioned.

 

If I change the timestamp to unix timestamp, the API call doesn't have a Bad Request, but it returns nothing. Even using unix_timestamp as 10, the response is empty. 

 

public_object_search_request = 
PublicObjectSearchRequest(filter_groups=[{"filters":[{"value":"10",
"propertyName":"hs_lastmodifieddate","operator":"GT"}]}],
properties=["hs_lastmodifieddate"], limit=0, after=0)

Thank you for your help.

0 Votes