mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Hubspot): Add support for Private App Token Authentication
* add Hubspot Private App Token Authentication * ⚡ Add credential verification * ⚡ Rename app token Co-authored-by: Rene Wagner <wagner@villacircle.com> Co-authored-by: Jan Oberhauser <janober@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,10 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
@@ -59,7 +62,7 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||
return await this.helpers.requestOAuth2!.call(this, 'hubspotOAuth2Api', options, { tokenType: 'Bearer', includeCredentialsOnRefreshOnBody: true });
|
||||
}
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1969,3 +1972,33 @@ export const getAssociations = (associations: {
|
||||
...(associations.ticketIds && { ticketIds: associations.ticketIds.toString().split(',') }),
|
||||
};
|
||||
};
|
||||
|
||||
export async function validateCredentials(
|
||||
this: ICredentialTestFunctions,
|
||||
decryptedCredentials: ICredentialDataDecryptedObject,
|
||||
): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = decryptedCredentials;
|
||||
|
||||
const {
|
||||
apiKey,
|
||||
appToken,
|
||||
} = credentials as {
|
||||
appToken: string,
|
||||
apiKey: string,
|
||||
};
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
method: 'GET',
|
||||
headers: {},
|
||||
uri: `https://api.hubapi.com/deals/v1/deal/paged`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (apiKey) {
|
||||
options.qs = { hapikey: apiKey };
|
||||
} else {
|
||||
options.headers = { Authorization: `Bearer ${appToken}` };
|
||||
}
|
||||
|
||||
return await this.helpers.request(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user