Skip to content

Commit

Permalink
Merge pull request #126 from iloveitaly/docs-paginate
Browse files Browse the repository at this point in the history
docs: pagination example
  • Loading branch information
amleczko authored May 7, 2024
2 parents 657d211 + 1a55f7e commit 94484c2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ def get_tasks_sync():
print(error)
```

Example of paginating through a completed project tasks:

```python
def get_all_completed_items(original_params: dict):
params = original_params.copy()
results = []

while True:
response = api.get_completed_items(**(params | {"limit": 100}))
results.append(response.items)

if not response.has_more:
break

params["cursor"] = response.next_cursor

# flatten the results
return [item for sublist in results for item in sublist]

items = get_all_completed_items({"project_id": 123})
```

### Documentation

For more detailed reference documentation, have a look at the [API documentation with Python examples](https://developer.todoist.com/rest/v2/?python).
Expand Down

0 comments on commit 94484c2

Please sign in to comment.