diff --git a/packages/nodes-base/nodes/FacebookAds/AdDescription.ts b/packages/nodes-base/nodes/FacebookAds/AdDescription.ts index 0a70e67d2f..4752e18d5d 100644 --- a/packages/nodes-base/nodes/FacebookAds/AdDescription.ts +++ b/packages/nodes-base/nodes/FacebookAds/AdDescription.ts @@ -13,18 +13,13 @@ export const adOperations = [ }, }, options: [ - { - name: 'Create', - value: 'create', - description: 'Create an ad.', - }, { name: 'Get', value: 'get', description: 'Get ads.', } ], - default: 'create', + default: 'get', description: 'The operation to perform.', }, { @@ -170,9 +165,6 @@ export const adFields = [ operation: [ 'get' ], - getBy: [ - 'adAccount' - ], }, }, options: [ @@ -262,46 +254,12 @@ export const adFields = [ ] }, { - displayName: 'Effective Status', - name: 'effectiveStatus', - type: 'fixedCollection', - description: 'Filter ads by effective status.', - typeOptions: { - multipleValues: true - }, - options: [ - { - displayName: 'Status Properties', - name: 'properties', - values: [ - { - displayName: 'Status', - name: 'status', - type: 'options', - default: '', - description: 'Effective status.', - options: [ - { - name: 'ACTIVE', - value: 'ACTIVE' - }, - { - name: 'ARCHIVED', - value: 'ARCHIVED' - }, - { - name: 'DELETED', - value: 'DELETED' - }, - { - name: 'PAUSED', - value: 'PAUSED' - }, - ] - } - ] - } - ] + displayName: 'Fields', + name: 'fields', + type: 'string', + description: 'Comma separated fields of ad item you want to retrieve.', + default: '', + placeholder: 'bid_amount,campaign' }, { displayName: 'Time Range', @@ -334,54 +292,6 @@ export const adFields = [ }, ] }, - { - displayName: 'Updated Since', - name: 'updatedSince', - type: 'number', - required: true, - description: 'Time since the Ad has been updated.', - default: '' - } ] }, - -/* -------------------------------------------------------------------------- */ -/* ad:create */ -/* -------------------------------------------------------------------------- */ - { - displayName: 'Ad Creative ID', - name: 'adCreativeId', - type: 'string', - required: true, - displayOptions: { - show: { - resource: [ - 'ad' - ], - operation: [ - 'create' - ], - }, - }, - description: 'ID of ad creative.', - default: '' - }, - { - displayName: 'Ad Set ID', - name: 'adSetId', - type: 'string', - required: true, - displayOptions: { - show: { - resource: [ - 'ad' - ], - operation: [ - 'create' - ], - }, - }, - description: 'ID of ad creative.', - default: '' - }, ] as INodeProperties[]; \ No newline at end of file diff --git a/packages/nodes-base/nodes/FacebookAds/AdInsightsDescription.ts b/packages/nodes-base/nodes/FacebookAds/AdInsightsDescription.ts index 4f49c5a620..8faf5e1194 100644 --- a/packages/nodes-base/nodes/FacebookAds/AdInsightsDescription.ts +++ b/packages/nodes-base/nodes/FacebookAds/AdInsightsDescription.ts @@ -484,7 +484,6 @@ export const adInsightsFields = [ displayName: 'Filters', name: 'filters', type: 'fixedCollection', - default: 'properties', description: 'Filters on the report data. This parameter is an array of filter objects.', typeOptions: { multipleValues: true diff --git a/packages/nodes-base/nodes/FacebookAds/FacebookAds.node.ts b/packages/nodes-base/nodes/FacebookAds/FacebookAds.node.ts index 23efadbacb..4000dec04f 100644 --- a/packages/nodes-base/nodes/FacebookAds/FacebookAds.node.ts +++ b/packages/nodes-base/nodes/FacebookAds/FacebookAds.node.ts @@ -68,7 +68,7 @@ export class FacebookAds implements INodeType { const operation = this.getNodeParameter('operation', 0) as string; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { - if (resource === 'adAccount' || resource === 'ad' || resource === 'adSet' || resource === 'adCampaign') { + if (resource === 'insightsReport') { if (operation === 'get' || operation === 'create') { const jsonParameters = this.getNodeParameter('jsonParameters', itemIndex) as boolean; const body : IAdInsightParameters = {}; @@ -182,7 +182,51 @@ export class FacebookAds implements INodeType { } } } + } + if (resource === 'ad') { + if (operation === 'get') { + const body : IAdInsightParameters = {}; + const itemId : string = this.getNodeParameter('itemId', itemIndex) as string; + const getBy : string = this.getNodeParameter('getBy', itemIndex) as string; + const additionalFields : IDataObject = this.getNodeParameter('additionalFields', itemIndex) as IDataObject; + + if (additionalFields) { + if (additionalFields.datePreset) { + body.date_preset = additionalFields.datePreset as string; + } + if (additionalFields.datePreset) { + body.fields = additionalFields.fields.split(',') as string[]; + } + if (additionalFields.timeRange) { + body.time_range = additionalFields.timeRange.properties as ITimeRange; + } + } + + let endpoint : string; + let method : string; + + if (getBy === 'id') { + endpoint = `${itemId}`; + method = 'GET'; + responseData = await facebookAdsApiRequest.call(this, method, endpoint, body); + } + if (getBy === 'adAccount') { + endpoint = `act_${itemId}/ads`; + method = 'GET'; + responseData = await facebookAdsApiRequest.call(this, method, endpoint, body); + } + if (getBy === 'adCampaign') { + endpoint = `${itemId}/ads`; + method = 'GET'; + responseData = await facebookAdsApiRequest.call(this, method, endpoint, body); + } + if (getBy === 'adSet') { + endpoint = `${itemId}/ads`; + method = 'GET'; + responseData = await facebookAdsApiRequest.call(this, method, endpoint, body); + } + } } if (Array.isArray(responseData)) {