rbw / pysnow

ServiceNow API Client Library
MIT License
203 stars 89 forks source link

can't get less than all values with sysparm_limit #21

Closed Carles-Figuerola closed 7 years ago

Carles-Figuerola commented 7 years ago

I am trying to get only a subset of a table, I saw that Client() has a default_payload and you can specify a sysparm_limit, but when I set it, when doing:

s = sn.Client('mysn', user, pwd, default_payload={"sysparm_limit": "2"})
request = s.query(table='mytable', query={})
response = request.get_all(fields=['sys_id', 'value'])
for each in response:
  print each

I get all the results, but paged through my sysparm_limit. I would prefer (or at least have the option to) to see only N results total.

rbw commented 7 years ago

Hello!

Using sysparm_limit does limit the result, however, link headers are still present on all responses by default. Pysnow follows links automatically and chains in one result. You can disable this (link headers) by passing {'sysparm_suppress_pagination_header': True} in default_payload.

Does that work for you?

I'll create a limit() method that does this automatically.

/Robert

Carles-Figuerola commented 7 years ago

Many thanks for the prompt response. That extra payload options does indeed stop the recurrence on the query, but as you say a limit() or do_not_follow_links() would be useful to not depend on servicenow's api options.

Thanks!

rbw commented 7 years ago

Hello,

Implemented in #23 , getting released in 0.3.2 (in a few days)

Thanks for reporting :)

Regards, Robert

rbw commented 7 years ago

Fixed.

You can now limit the number records returned from the SN API by passing limit to get_all()

Docs: http://pysnow.readthedocs.io/en/latest/_modules/pysnow.html#Request.get_all