File tree Expand file tree Collapse file tree 5 files changed +79
-0
lines changed
Node/DisplayListOfContacts Expand file tree Collapse file tree 5 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ ** /* .idea
2+ ** /* .iml
Original file line number Diff line number Diff line change 1+ yarn.lock
2+ node_modules
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments