VeritasOS / netbackup-api-code-samples

Contains code samples that demonstrate the use of NetBackup REST API
MIT License
53 stars 52 forks source link

Use Python requests module to query jobs, and use filter parameter to report errors #46

Closed lordrocyu closed 5 years ago

lordrocyu commented 5 years ago

NBU ver:8.1.2 OS:RedHat 7.2

When I use the requests to get yesterday jobs with query_params = { "filter":"startTime lt '2019-10-30T00:00:00Z'" ,
}

The url will be translate to https://nbuserver:1556/netbackup/admin/jobs/?filter=startTime+lt+%272019-10-30T00%3A00%3A00Z%27

Python report:

Traceback (most recent call last): File "C:/Users/roc/Desktop/python/nbu/api_requests.py", line 133, in res = get_netbackup_job(jwt, baseurl) File "C:/Users/roc/Desktop/python/nbu/api_requests.py", line 121, in get_netbackup_job raise Exception('Alert API failed with status code {} and {}'.format(resp.status_code, resp.json())) Exception: Alert API failed with status code 400 and {'errorCode': 9401, 'errorMessage': "The OData filter criteria is invalid. The types 'Edm.DateTimeOffset' and 'Edm.String' are not compatible.", 'details': {}}

ajmathews commented 5 years ago

It seems like the timestamp format is not as expected.

query_params = {
"filter":"startTime lt 2019-10-30T00:00:00.000Z" 
}

Hope this helps

lordrocyu commented 5 years ago

It seems like the timestamp format is not as expected.

  • Remove the single quotes around the timestamp
  • Adjust the timestamp to be in the format 2019-10-30T00:00:00.000Z
query_params = {
"filter":"startTime lt 2019-10-30T00:00:00.000Z" 
}

Hope this helps

Thanks. Just it. I get the jobs.