Skip to content

Commit

Permalink
other: Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Omazepa committed Jul 27, 2022
1 parent 665068d commit 3c32f1b
Showing 1 changed file with 167 additions and 1 deletion.
168 changes: 167 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ The following service methods are available to instantiated clients. The example
- [createMembers](#createmembers)
- [updateMember](#updatemember)
- [destroyMember](#destroymember)
- [Navigation thru lists](#navigation-thru-lists)
- [Browser Demo](#browser-demo)
- [Development](#development)
- [Requirements](#requirements)
Expand Down Expand Up @@ -1793,13 +1794,178 @@ mg.lists.members.destroyMember('[email protected]', '[email protected]')
Promise Returns: response body
```
```js
{
member: { address: '[email protected]' },
message: 'Mailing list member has been deleted'
}
```
## Navigation thru lists
Most of the methods that return items in a list support pagination.
There are two ways to receive part of the list:
1. Provide properties 'limit' and 'page' in the query.
This way uses more frequently in the SDK and works for the next methods:
- mg.domains.domainTags.list()
- mg.domains.domainTemplates.list()
- mg.domains.domainTemplates.listVersions()
- mg.events.get()
- mg.lists.list()
- mg.lists.members.listMembers()
- mg.validate.list()
- mg.suppressions.list()
The general idea is that after you made the first call with a limit property in the query you will receive a response with a property called pages in it. This property implements the next interface:
```TS
{
previous: {
id: string;
page: string;
iteratorPosition: string | undefined;
url: string
};
first: {
id: string;
page: string;
iteratorPosition: string | undefined;
url: string
};
last: {
id: string;
page: string;
iteratorPosition: string | undefined;
url: string
};
next: {
id: string;
page: string;
iteratorPosition: string | undefined;
url: string
};
}
```
To receive the next page you need to add the page property to the query argument. This property should contain a string value from 'page' property in response.pages.(previous/first/last/next).
Example:
```Js
// first call
const listMembers = await mg.lists.members.listMembers('your_mailing_list', { limit: 2 });

/* response
{
items: [
{
address: '[email protected]',
name: 'test name 0',
subscribed: true,
vars: [Object]
},
{
address: '[email protected]',
name: 'test name 1',
subscribed: true,
vars: [Object]
}
],
pages: {
first: {
id: 'first',
page: '?page=first&limit=2',
iteratorPosition: undefined,
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=first&limit=2'
},
last: {
id: 'last',
page: '?page=last&limit=2',
iteratorPosition: undefined,
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=last&limit=2'
},
next: {
id: 'next',
page: '?page=next&address=test-1%40example.com&limit=2',
iteratorPosition: '[email protected]',
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=next&address=test-1%40example.com&limit=2'
},
previous: {
id: 'previous',
page: '?page=prev&address=test-0%40example.com&limit=2',
iteratorPosition: '[email protected]',
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=prev&address=test-0%40example.com&limit=2'
}
}
}
*/
// second call
const listMembers = await mg.lists.members.listMembers(
'your_mailing_list',
{
limit: 2,
page: '?page=next&address=test-1%40example.com&limit=2'
}
);

/* response
{
items: [
{
address: '[email protected]',
name: 'test name 2',
subscribed: true,
vars: [Object]
},
{
address: '[email protected]',
name: 'test name 3',
subscribed: true,
vars: [Object]
}
],
pages: {
first: {
id: 'first',
page: '?page=first&limit=2',
iteratorPosition: undefined,
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=first&limit=2'
},
last: {
id: 'last',
page: '?page=last&limit=2',
iteratorPosition: undefined,
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=last&limit=2'
},
next: {
id: 'next',
page: '?page=next&address=test-3%40example.com&limit=2',
iteratorPosition: '[email protected]',
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=next&address=test-3%40example.com&limit=2'
},
previous: {
id: 'previous',
page: '?page=prev&address=test-2%40example.com&limit=2',
iteratorPosition: '[email protected]',
url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=prev&address=test-2%40example.com&limit=2'
}
}
}
*/
```
2. The second option of navigation is to provide properties 'limit' and 'skip' in the query. This way uses only in a few places for now:
- mg.domains.list()
- mg.domains.domainCredentials.list()
- mg.routes.list()
- mg.webhooks.list()
The main idea here is quite simple you just need to provide how many records from the start of a list you want to skip and how many to receive. You can do it using the query parameter in each method.
Example:
```js
const listDomainCredentials = await client.domains.domainCredentials.list(
'your_domain_name',
{
skip: 10,
limit: 1
}
);
```
## Browser Demo
Expand Down

0 comments on commit 3c32f1b

Please sign in to comment.