Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.idea
**/*.iml
2 changes: 2 additions & 0 deletions Node/DisplayListOfContacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn.lock
node_modules
14 changes: 14 additions & 0 deletions Node/DisplayListOfContacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Description
Performs a call to the REST API to retrieve a list of Contact records, then displays them on the console.

## Instructions
* [Install Node](https://nodejs.org/en/download/) as the execution environment
* [Install Yarn](https://classic.yarnpkg.com/en/docs/install) as a package manager
* [Create a Personal Access Token](https://developer.infusionsoft.com/pat-and-sak/) in your Keap application instance
* In this directory:
* `yarn install`
* `node . --apikey insert-your-PAT`

## Next Steps
* See [developer.keap.com](https://developer.keap.com) for details on our REST APIs
* Join [community.keap.com](https://community.keap.com) for discussions and questions
48 changes: 48 additions & 0 deletions Node/DisplayListOfContacts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const yargs = require('yargs');
const axios = require('axios');
const axiosRetry = require('axios-retry');

axiosRetry(axios, { retries: 3 });

const API_BASE = `https://api.infusionsoft.com/crm/rest`;

const argv = yargs
.option('apikey', {
alias: 'a',
description: 'A Personal Access Token from your Keap application instance',
type: 'string',
})
.help()
.argv;

if(!argv.apikey) {
throw new Error('Must specify APIKey');
}

const REQUEST_HEADERS = {
'X-Keap-API-Key': argv.apikey,
'Content-Type': 'application/json'
}

async function getContacts() {
const axiosResponse =
await axios.get(
`${API_BASE}/v2/contacts`,
{
headers: REQUEST_HEADERS,
params: {}
});

const contactRecords = axiosResponse.data.contacts;

for(const contact of contactRecords) {
console.log(contact.id, contact.given_name, contact.family_name)
}
}

getContacts()
.catch(error => {
console.error(error);
})


13 changes: 13 additions & 0 deletions Node/DisplayListOfContacts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "DisplayListOfContacts",
"version": "1.0.0",
"description": "Display a list of Contacts retrieved from the Keap API",
"main": "index.js",
"author": "api@keap.com",
"license": "MIT",
"dependencies": {
"axios": "^0.24.0",
"axios-retry": "^3.2.4",
"yargs": "^17.2.1"
}
}