Get all messages with paginated results
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md
ISSUE_TEMPLATE.md
LICENSE
PULLREQUEST.md
PULL_REQUEST_TEMPLATE.md
README.md
getAllMessages.js
package.json

README.md

Catapult Node.js SDK Example

Get all Messages

Please note: This example is using the node-bandwidth 2.0 branch which is currently in a "developer preview" state, meaning it could change a lot. The package.json file included with this example references a specific version that will work, but the latest version may not.

The Catapult API will paginate messages results if there are more messages in the database than will fit in the size of a single page. The default size is 25. This means that multiple requests will need to be made to get all the messages on all the pages.

This example app uses the Node.js SDK for Catapult to get all of a users's messages, even if they do not all come back in a single REST API query. It uses the new feature of the SDK to navigate the link header returned in the REST API response, and query for all subsequent pages of results, until it has all of them. The results are printed out to the console in JSON format, just like they come back from the API.

Usage

Start by cloning this repo:

$ git clone https://github.com/BandwidthExamples/node-example-get-all-messages.git

Go into the new directory:

$ cd node-example-get-all-messages

Install the SDK and dependencies:

$ npm install

Update the getAllMessages.js and put in your own Catapult credentials, in the section that looks like this:

var client = new CatapultClient({
	userId    : "YOUR_USER_ID", // <-- note, this is not the same as the username you used to login to the portal
	apiToken  : "YOUR_API_TOKEN",
	apiSecret : "YOUR_API_SECRET"
});

Run it!

$ node getAllMessages

The results are printed to the console in JSON format, just like they come back from the API. All messages are included in a single array. If you want to pipe this out to a file you can run:

$ node getAllMessages >> output.json