mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Refactor out extra credentials parameter
This commit is contained in:
parent
878e2093db
commit
a885518019
|
@ -53,28 +53,12 @@ export class ZohoOAuth2Api implements ICredentialType {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'CN - https://accounts.zoho.com.cn/oauth/v2/token',
|
name: 'CN - https://accounts.zoho.com.cn/oauth/v2/token',
|
||||||
value: ' https://accounts.zoho.com.cn/oauth/v2/token',
|
value: 'https://accounts.zoho.com.cn/oauth/v2/token',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'https://accounts.zoho.com/oauth/v2/token',
|
default: 'https://accounts.zoho.com/oauth/v2/token',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Region',
|
|
||||||
name: 'region',
|
|
||||||
type: 'options' as NodePropertyTypes,
|
|
||||||
default: 'europe',
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'Europe',
|
|
||||||
value: 'europe',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'United States',
|
|
||||||
value: 'unitedStates',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Scope',
|
displayName: 'Scope',
|
||||||
name: 'scope',
|
name: 'scope',
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
NodeApiError,
|
NodeApiError,
|
||||||
NodeOperationError,
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -27,8 +26,7 @@ export async function zohoApiRequest(
|
||||||
) {
|
) {
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
const { region } = this.getCredentials('zohoOAuth2Api') as { region: 'europe' | 'unitedStates' };
|
const { oauthTokenData: { api_domain: apiDomain } } = this.getCredentials('zohoOAuth2Api') as { oauthTokenData: { api_domain: string} };
|
||||||
const tld = getTld(region);
|
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
body: {
|
body: {
|
||||||
|
@ -38,7 +36,7 @@ export async function zohoApiRequest(
|
||||||
},
|
},
|
||||||
method,
|
method,
|
||||||
qs,
|
qs,
|
||||||
uri: uri ?? `https://www.zohoapis.${tld}/crm/v2${endpoint}`,
|
uri: uri ?? `${apiDomain}/crm/v2${endpoint}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,7 +49,7 @@ export async function zohoApiRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(JSON.stringify(options.body.data, null, 2));
|
console.log(JSON.stringify(options, null, 2));
|
||||||
const responseData = await this.helpers.requestOAuth2.call(this, 'zohoOAuth2Api', options);
|
const responseData = await this.helpers.requestOAuth2.call(this, 'zohoOAuth2Api', options);
|
||||||
return operation === 'getAll' ? responseData : responseData.data;
|
return operation === 'getAll' ? responseData : responseData.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -151,9 +149,6 @@ function hasAddressFields(locationField: unknown): locationField is LocationFiel
|
||||||
return locationField.hasOwnProperty('address_fields');
|
return locationField.hasOwnProperty('address_fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTld = (region: 'europe' | 'unitedStates') =>
|
|
||||||
({ europe: 'eu', unitedStates: 'com' }[region]);
|
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
// types
|
// types
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue