Salesforce (#932)

* fix salesforce error while get all using nextRecordsUrl

The uri for using nextRecordsUrl to get all data in salesforce node is error. The right usage is fixed in this pr.

*  Small changes

* :zap Small fix

Co-authored-by: YErii <yeriime@outlook.com>
Co-authored-by: Jan <janober@users.noreply.github.com>
This commit is contained in:
Ricardo Espinoza 2020-09-06 15:31:55 -04:00 committed by GitHub
parent 5a0e356ab6
commit d64c767ebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 10 deletions

View file

@ -36,11 +36,11 @@ export class PagerDutyOAuth2Api implements ICredentialType {
default: '',
},
{
displayName: 'Authentication',
name: 'authentication',
type: 'hidden' as NodePropertyTypes,
default: 'header',
description: 'Method of authentication.',
},
displayName: 'Authentication',
name: 'authentication',
type: 'hidden' as NodePropertyTypes,
default: 'header',
description: 'Method of authentication.',
},
];
}

View file

@ -37,5 +37,12 @@ export class SalesforceOAuth2Api implements ICredentialType {
type: 'hidden' as NodePropertyTypes,
default: '',
},
{
displayName: 'Authentication',
name: 'authentication',
type: 'hidden' as NodePropertyTypes,
default: 'header',
description: 'Method of authentication.',
},
];
}

View file

@ -1,21 +1,25 @@
import { OptionsWithUri } from 'request';
import {
OptionsWithUri,
} from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import {
IDataObject
} from 'n8n-workflow';
export async function salesforceApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function salesforceApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('salesforceOAuth2Api');
const subdomain = ((credentials!.accessTokenUrl as string).match(/https:\/\/(.+).salesforce\.com/) || [])[1];
const options: OptionsWithUri = {
method,
body: method === "GET" ? undefined : body,
qs,
uri: uri || `https://${subdomain}.salesforce.com/services/data/v39.0${resource}`,
uri: `https://${subdomain}.salesforce.com/services/data/v39.0${uri || endpoint}`,
json: true
};
try {
@ -39,7 +43,7 @@ export async function salesforceApiRequestAllItems(this: IExecuteFunctions | ILo
do {
responseData = await salesforceApiRequest.call(this, method, endpoint, body, query, uri);
uri = responseData.nextRecordsUrl;
uri = `${endpoint}/${responseData.nextRecordsUrl?.split('/')?.pop()}`;
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData.nextRecordsUrl !== undefined &&

View file

@ -15,66 +15,84 @@ import {
accountFields,
accountOperations,
} from './AccountDescription';
import {
IAccount,
} from './AccountInterface';
import {
attachmentFields,
attachmentOperations,
} from './AttachmentDescription';
import {
IAttachment,
} from './AttachmentInterface';
import {
ICampaignMember,
} from './CampaignMemberInterface';
import {
caseFields,
caseOperations,
} from './CaseDescription';
import {
ICase,
ICaseComment,
} from './CaseInterface';
import {
contactFields,
contactOperations,
} from './ContactDescription';
import {
IContact,
} from './ContactInterface';
import {
salesforceApiRequest,
salesforceApiRequestAllItems,
} from './GenericFunctions';
import {
leadFields,
leadOperations,
} from './LeadDescription';
import {
ILead,
} from './LeadInterface';
import {
INote,
} from './NoteInterface';
import {
opportunityFields,
opportunityOperations,
} from './OpportunityDescription';
import {
IOpportunity,
} from './OpportunityInterface';
import {
taskFields,
taskOperations,
} from './TaskDescription';
import {
ITask,
} from './TaskInterface';
import {
userFields,
userOperations,
} from './UserDescription';
import {
IUser,
} from './UserInterface';