Skip to content

Commit 9fde1c2

Browse files
Merge pull request #80 from mailjet/dnefodov/feature/add-filtering-to-doc
Add filters usage documentation
2 parents 0d660c9 + b7cdaa3 commit 9fde1c2

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ nosetests.xml
2929
coverage.xml
3030
junit*
3131
build/
32-
dist/
32+
dist/
33+
venv/

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Check out all the resources and Python code examples in the official [Mailjet Do
3232
- [Using actions](#using-actions)
3333
- [GET request](#get-request)
3434
- [Retrieve all objects](#retrieve-all-objects)
35-
- [Use filtering](#use-filtering)
35+
- [Using filtering](#using-filtering)
36+
- [Using pagination](#using-pagination)
3637
- [Retrieve a single object](#retrieve-a-single-object)
3738
- [PUT request](#put-request)
3839
- [DELETE request](#delete-request)
@@ -236,6 +237,32 @@ print result.status_code
236237
print result.json()
237238
```
238239

240+
#### Using pagination
241+
242+
Some requests (for example [GET /contact](https://dev.mailjet.com/email/reference/contacts/contact/#v3_get_contact)) has `limit`, `offset` and `sort` query string parameters. These parameters could be used for pagination.
243+
`limit` `int` Limit the response to a select number of returned objects. Default value: `10`. Maximum value: `1000`
244+
`offset` `int` Retrieve a list of objects starting from a certain offset. Combine this query parameter with `limit` to retrieve a specific section of the list of objects. Default value: `0`
245+
`sort` `str` Sort the results by a property and select ascending (ASC) or descending (DESC) order. The default order is ascending. Keep in mind that this is not available for all properties. Default value: `ID asc`
246+
Next example returns 40 contacts starting from 51th record sorted by `Email` field descendally:
247+
248+
```python
249+
import os
250+
from mailjet_rest import Client
251+
252+
api_key = os.environ["MJ_APIKEY_PUBLIC"]
253+
api_secret = os.environ["MJ_APIKEY_PRIVATE"]
254+
mailjet = Client(auth=(api_key, api_secret))
255+
256+
filters = {
257+
"limit": 40,
258+
"offset": 50,
259+
"sort": "Email desc",
260+
}
261+
result = mailjet.contact.get(filters=filters)
262+
print(result.status_code)
263+
print(result.json())
264+
```
265+
239266
#### Retrieve a single object
240267

241268
```python

0 commit comments

Comments
 (0)