🔀 Merge branch 'RicardoE105-feature/extend-hubspot'

This commit is contained in:
Jan Oberhauser 2020-03-29 10:18:17 +02:00
commit dca04fa02a

View file

@ -258,12 +258,8 @@ export class Hubspot implements INodeType {
}); });
} }
body.associations = association; body.associations = association;
try { const endpoint = '/deals/v1/deal';
const endpoint = '/deals/v1/deal'; responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
} }
if (operation === 'update') { if (operation === 'update') {
const body: IDeal = {}; const body: IDeal = {};
@ -311,12 +307,8 @@ export class Hubspot implements INodeType {
value: updateFields.pipeline as string value: updateFields.pipeline as string
}); });
} }
try { const endpoint = `/deals/v1/deal/${dealId}`;
const endpoint = `/deals/v1/deal/${dealId}`; responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
} }
if (operation === 'get') { if (operation === 'get') {
const dealId = this.getNodeParameter('dealId', i) as string; const dealId = this.getNodeParameter('dealId', i) as string;
@ -324,12 +316,8 @@ export class Hubspot implements INodeType {
if (additionalFields.includePropertyVersions) { if (additionalFields.includePropertyVersions) {
qs.includePropertyVersions = additionalFields.includePropertyVersions as boolean; qs.includePropertyVersions = additionalFields.includePropertyVersions as boolean;
} }
try { const endpoint = `/deals/v1/deal/${dealId}`;
const endpoint = `/deals/v1/deal/${dealId}`; responseData = await hubspotApiRequest.call(this, 'GET', endpoint);
responseData = await hubspotApiRequest.call(this, 'GET', endpoint);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
} }
if (operation === 'getAll') { if (operation === 'getAll') {
const filters = this.getNodeParameter('filters', i) as IDataObject; const filters = this.getNodeParameter('filters', i) as IDataObject;
@ -345,17 +333,13 @@ export class Hubspot implements INodeType {
// @ts-ignore // @ts-ignore
qs.propertiesWithHistory = filters.propertiesWithHistory.split(','); qs.propertiesWithHistory = filters.propertiesWithHistory.split(',');
} }
try { const endpoint = `/deals/v1/deal/paged`;
const endpoint = `/deals/v1/deal/paged`; if (returnAll) {
if (returnAll) { responseData = await hubspotApiRequestAllItems.call(this, 'deals', 'GET', endpoint, {}, qs);
responseData = await hubspotApiRequestAllItems.call(this, 'deals', 'GET', endpoint, {}, qs); } else {
} else { qs.limit = this.getNodeParameter('limit', 0) as number;
qs.limit = this.getNodeParameter('limit', 0) as number; responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs); responseData = responseData.deals;
responseData = responseData.deals;
}
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
} }
} }
if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') { if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') {
@ -368,31 +352,23 @@ export class Hubspot implements INodeType {
if (filters.includePropertyVersions) { if (filters.includePropertyVersions) {
qs.includePropertyVersions = filters.includePropertyVersions as boolean; qs.includePropertyVersions = filters.includePropertyVersions as boolean;
} }
try { if (operation === 'getRecentlyCreated') {
if (operation === 'getRecentlyCreated') { endpoint = `/deals/v1/deal/recent/created`;
endpoint = `/deals/v1/deal/recent/created`; } else {
} else { endpoint = `/deals/v1/deal/recent/modified`;
endpoint = `/deals/v1/deal/recent/modified`; }
} if (returnAll) {
if (returnAll) { responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs);
responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs); } else {
} else { qs.count = this.getNodeParameter('limit', 0) as number;
qs.count = this.getNodeParameter('limit', 0) as number; responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs); responseData = responseData.results;
responseData = responseData.results;
}
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
} }
} }
if (operation === 'delete') { if (operation === 'delete') {
const dealId = this.getNodeParameter('dealId', i) as string; const dealId = this.getNodeParameter('dealId', i) as string;
try { const endpoint = `/deals/v1/deal/${dealId}`;
const endpoint = `/deals/v1/deal/${dealId}`; responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
} }
} }
//https://developers.hubspot.com/docs/methods/forms/forms_overview //https://developers.hubspot.com/docs/methods/forms/forms_overview