File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,24 @@ client.events.create({
109109});
110110```
111111
112+ ## Pagination
113+
114+ When listing, the Intercom API may return a pagination object:
115+
116+ ``` json
117+ {
118+ "pages" : {
119+ "next" : " ..."
120+ }
121+ }
122+ ```
123+
124+ You can grab the next page of results using the client:
125+
126+ ```
127+ client.nextPage(response.pages, callback);
128+ ```
129+
112130## License
113131
114132Apache-2.0
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ export class Client {
3434 . header ( 'Accept' , 'application/json' )
3535 . end ( r => f ( r ) ) ;
3636 }
37+ nextPage ( paginationObject , f ) {
38+ unirest . get ( paginationObject . next )
39+ . auth ( this . appId , this . appApiKey )
40+ . type ( 'json' )
41+ . header ( 'Accept' , 'application/json' )
42+ . end ( r => f ( r ) ) ;
43+ }
3744 delete ( endpoint , data , f ) {
3845 unirest . delete ( `https://api.intercom.io${ endpoint } ` )
3946 . auth ( this . appId , this . appApiKey )
Original file line number Diff line number Diff line change @@ -16,4 +16,13 @@ describe('clients', function () {
1616 done ( ) ;
1717 } ) ;
1818 } ) ;
19+ it ( 'paginate' , function ( done ) {
20+ nock ( 'https://api.intercom.io' ) . get ( '/foo/bar/baz' ) . query ( { blue : 'red' } ) . reply ( 200 , { foo : 'bar' } ) ;
21+ let client = new Client ( 'foo' , 'bar' ) ;
22+ let paginationObject = { next : 'https://api.intercom.io/foo/bar/baz?blue=red' } ;
23+ client . nextPage ( paginationObject , function ( r ) {
24+ assert . deepEqual ( { foo : 'bar' } , r . body ) ;
25+ done ( ) ;
26+ } ) ;
27+ } ) ;
1928} ) ;
You can’t perform that action at this time.
0 commit comments