Skip to content

Commit 4588b6e

Browse files
authored
Merge pull request #16 from infusionsoft/Hackathon_Examples_Node
Adding Node example
2 parents 39924bf + 319de73 commit 4588b6e

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*.idea
2+
**/*.iml
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn.lock
2+
node_modules
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Description
2+
Performs a call to the REST API to retrieve a list of Contact records, then displays them on the console.
3+
4+
## Instructions
5+
* [Install Node](https://nodejs.org/en/download/) as the execution environment
6+
* [Install Yarn](https://classic.yarnpkg.com/en/docs/install) as a package manager
7+
* [Create a Personal Access Token](https://developer.infusionsoft.com/pat-and-sak/) in your Keap application instance
8+
* In this directory:
9+
* `yarn install`
10+
* `node . --apikey insert-your-PAT`
11+
12+
## Next Steps
13+
* See [developer.keap.com](https://developer.keap.com) for details on our REST APIs
14+
* Join [community.keap.com](https://community.keap.com) for discussions and questions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const yargs = require('yargs');
2+
const axios = require('axios');
3+
const axiosRetry = require('axios-retry');
4+
5+
axiosRetry(axios, { retries: 3 });
6+
7+
const API_BASE = `https://api.infusionsoft.com/crm/rest`;
8+
9+
const argv = yargs
10+
.option('apikey', {
11+
alias: 'a',
12+
description: 'A Personal Access Token from your Keap application instance',
13+
type: 'string',
14+
})
15+
.help()
16+
.argv;
17+
18+
if(!argv.apikey) {
19+
throw new Error('Must specify APIKey');
20+
}
21+
22+
const REQUEST_HEADERS = {
23+
'X-Keap-API-Key': argv.apikey,
24+
'Content-Type': 'application/json'
25+
}
26+
27+
async function getContacts() {
28+
const axiosResponse =
29+
await axios.get(
30+
`${API_BASE}/v2/contacts`,
31+
{
32+
headers: REQUEST_HEADERS,
33+
params: {}
34+
});
35+
36+
const contactRecords = axiosResponse.data.contacts;
37+
38+
for(const contact of contactRecords) {
39+
console.log(contact.id, contact.given_name, contact.family_name)
40+
}
41+
}
42+
43+
getContacts()
44+
.catch(error => {
45+
console.error(error);
46+
})
47+
48+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "DisplayListOfContacts",
3+
"version": "1.0.0",
4+
"description": "Display a list of Contacts retrieved from the Keap API",
5+
"main": "index.js",
6+
"author": "api@keap.com",
7+
"license": "MIT",
8+
"dependencies": {
9+
"axios": "^0.24.0",
10+
"axios-retry": "^3.2.4",
11+
"yargs": "^17.2.1"
12+
}
13+
}

0 commit comments

Comments
 (0)