Applying filters on google apl

I am trying to get the job ids, args, state and other fields from the API ml.googleapis.com. I want to filter the APIto list the jobids for a start date and end date. I have to create this as a job that will run for multiple projects every day. So this cannot be done from the gshell. I tried the following code and it is giving errors.

  from googleapiclient import discovery
    from googleapiclient import errors
    project_id = 'projects/a'.format('gcp-scj3-host-scj-core-01')
    ml = discovery.build('ml', 'v1')
    request = ml.projects().jobs().list(parent=project_id,filter="createTime>=2021-10-21T12:00:00" and "createTime<=2021-10-22T12:00:00")
    response = request.execute()
    print(response)

The error I am getting is Invalid syntax or TypeError: unhashable type: ‘list'. It will be gerat to know how to apply the filter for dates when making a request to the API. Thanks.

1 answer

  • answered 2021-10-23 23:27 DazWilkin

    I'm unable to try this but think it's likely a string issue.

    Please try:

    filter="createTime>=2021-10-21T12:00:00 and createTime<=2021-10-22T12:00:00"
    

    It can be very helpful (to eliminate other errors) to use Google APIs Explorer to invoke ("Try this API") the underlying method from a browser.

    Here's the page for this method:

    https://cloud.google.com/ai-platform/training/docs/reference/rest/v1/projects.jobs/list

    You can play around with filters more easily and then plug a working filter into your code.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum