1- import LinkedApi from 'linkedapi-node' ;
1+ import LinkedApi , { LinkedApiError , LinkedApiWorkflowError } from 'linkedapi-node' ;
22
33async function connectionsExample ( ) : Promise < void > {
44
55 const linkedapi = new LinkedApi ( {
6- accountApiToken : process . env . ACCOUNT_API_TOKEN ,
7- identificationToken : process . env . IDENTIFICATION_TOKEN ,
8- dataApiToken : process . env . DATA_API_TOKEN ,
6+ apiToken : process . env . API_TOKEN ! ,
7+ identificationToken : process . env . IDENTIFICATION_TOKEN ! ,
98 } ) ;
109
1110 try {
@@ -22,10 +21,10 @@ async function connectionsExample(): Promise<void> {
2221 await removeConnection ( linkedapi , targetPersonUrl2 ) ;
2322
2423 } catch ( error ) {
25- if ( error instanceof LinkedApi . LinkedApiError ) {
24+ if ( error instanceof LinkedApiError ) {
2625 console . error ( '🚨 Linked API Error:' , error . message ) ;
2726 console . error ( '📝 Details:' , error . details ) ;
28- } else if ( error instanceof LinkedApi . LinkedApiWorkflowError ) {
27+ } else if ( error instanceof LinkedApiWorkflowError ) {
2928 console . error ( '🚨 Linked API Workflow Error:' , error . message ) ;
3029 console . error ( '🔍 Reason:' , error . reason ) ;
3130 } else {
@@ -41,7 +40,7 @@ async function checkConnectionStatus(linkedapi: LinkedApi, personUrl: string): P
4140 personUrl : personUrl ,
4241 } ;
4342
44- const statusWorkflow = await linkedapi . account . checkConnectionStatus ( statusParams ) ;
43+ const statusWorkflow = await linkedapi . checkConnectionStatus ( statusParams ) ;
4544 console . log ( '🔍 Connection status workflow started:' , statusWorkflow . workflowId ) ;
4645
4746 const statusResult = await statusWorkflow . result ( ) ;
@@ -58,7 +57,7 @@ async function sendConnectionRequest(linkedapi: LinkedApi, personUrl: string): P
5857 email : 'example@gmail.com' ,
5958 } ;
6059
61- const requestWorkflow = await linkedapi . account . sendConnectionRequest ( requestParams ) ;
60+ const requestWorkflow = await linkedapi . sendConnectionRequest ( requestParams ) ;
6261 console . log ( '📤 Send connection request workflow started:' , requestWorkflow . workflowId ) ;
6362
6463 await requestWorkflow . result ( ) ;
@@ -69,7 +68,7 @@ async function sendConnectionRequest(linkedapi: LinkedApi, personUrl: string): P
6968async function retrievePendingRequests ( linkedapi : LinkedApi ) : Promise < void > {
7069 console . log ( '\n📋 Retrieving pending connection requests...' ) ;
7170
72- const pendingWorkflow = await linkedapi . account . retrievePendingRequests ( ) ;
71+ const pendingWorkflow = await linkedapi . retrievePendingRequests ( ) ;
7372 console . log ( '📋 Retrieve pending requests workflow started:' , pendingWorkflow . workflowId ) ;
7473
7574 const pendingResults = await pendingWorkflow . result ( ) ;
@@ -91,7 +90,7 @@ async function withdrawConnectionRequest(linkedapi: LinkedApi, personUrl: string
9190 unfollow : true ,
9291 } ;
9392
94- const withdrawWorkflow = await linkedapi . account . withdrawConnectionRequest ( withdrawParams ) ;
93+ const withdrawWorkflow = await linkedapi . withdrawConnectionRequest ( withdrawParams ) ;
9594 console . log ( '🔙 Withdraw connection request workflow started:' , withdrawWorkflow . workflowId ) ;
9695
9796 await withdrawWorkflow . result ( ) ;
@@ -110,7 +109,7 @@ async function retrieveConnections(linkedapi: LinkedApi): Promise<void> {
110109 } ,
111110 } ;
112111
113- const connectionsWorkflow = await linkedapi . account . retrieveConnections ( connectionsParams ) ;
112+ const connectionsWorkflow = await linkedapi . retrieveConnections ( connectionsParams ) ;
114113 console . log ( '👥 Retrieve connections workflow started:' , connectionsWorkflow . workflowId ) ;
115114
116115 const connectionsResults = await connectionsWorkflow . result ( ) ;
@@ -132,23 +131,14 @@ async function removeConnection(linkedapi: LinkedApi, personUrl: string): Promis
132131 personUrl : personUrl ,
133132 } ;
134133
135- const removeWorkflow = await linkedapi . account . removeConnection ( removeParams ) ;
134+ const removeWorkflow = await linkedapi . removeConnection ( removeParams ) ;
136135 console . log ( '❌ Remove connection workflow started:' , removeWorkflow . workflowId ) ;
137136
138137 await removeWorkflow . result ( ) ;
139138 console . log ( '✅ Connection removed successfully' ) ;
140139 console . log ( ' 🔗 No longer connected with this person' ) ;
141140}
142141
143- async function runExample ( ) : Promise < void > {
144- try {
145- await connectionsExample ( ) ;
146- } catch ( error ) {
147- console . error ( '💥 Example failed:' , error ) ;
148- process . exit ( 1 ) ;
149- }
150- }
151-
152142if ( require . main === module ) {
153- runExample ( ) ;
143+ connectionsExample ( ) ;
154144}
0 commit comments