mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Small changes to FacebookGraphAPI-Node
This commit is contained in:
parent
c0c281995a
commit
4f83d29afe
|
@ -4,9 +4,9 @@ import {
|
|||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export class GraphApi implements ICredentialType {
|
||||
name = 'graphApi';
|
||||
displayName = 'Graph API';
|
||||
export class FacebookGraphApi implements ICredentialType {
|
||||
name = 'facebookGraphApi';
|
||||
displayName = 'Facebook Graph API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Access Token',
|
|
@ -12,24 +12,23 @@ import {
|
|||
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
export class GraphApi implements INodeType {
|
||||
export class FacebookGraphApi implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Graph API',
|
||||
name: 'graphApi',
|
||||
displayName: 'Facebook Graph API',
|
||||
name: 'facebookGraphApi',
|
||||
icon: 'file:facebook.png',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Interacts with Facebook using the Graph API',
|
||||
defaults: {
|
||||
name: 'Graph API',
|
||||
name: 'Facebook Graph API',
|
||||
color: '#772244',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main', 'main'],
|
||||
outputNames: ['success', 'failure'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'graphApi',
|
||||
name: 'facebookGraphApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
@ -85,35 +84,35 @@ export class GraphApi implements INodeType {
|
|||
},
|
||||
{
|
||||
name: 'v6.0',
|
||||
value: 'v6.0/',
|
||||
value: 'v6.0',
|
||||
},
|
||||
{
|
||||
name: 'v5.0',
|
||||
value: 'v5.0/',
|
||||
value: 'v5.0',
|
||||
},
|
||||
{
|
||||
name: 'v4.0',
|
||||
value: 'v4.0/',
|
||||
value: 'v4.0',
|
||||
},
|
||||
{
|
||||
name: 'v3.3',
|
||||
value: 'v3.3/',
|
||||
value: 'v3.3',
|
||||
},
|
||||
{
|
||||
name: 'v3.2',
|
||||
value: 'v3.2/',
|
||||
value: 'v3.2',
|
||||
},
|
||||
{
|
||||
name: 'v3.1',
|
||||
value: 'v3.1/',
|
||||
value: 'v3.1',
|
||||
},
|
||||
{
|
||||
name: 'v3.0',
|
||||
value: 'v3.0/',
|
||||
value: 'v3.0',
|
||||
},
|
||||
{
|
||||
name: 'v2.12',
|
||||
value: 'v2.12/',
|
||||
value: 'v2.12',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
|
@ -270,19 +269,22 @@ export class GraphApi implements INodeType {
|
|||
const items = this.getInputData();
|
||||
|
||||
let response: any; // tslint:disable-line:no-any
|
||||
const successItems: INodeExecutionData[] = [];
|
||||
const failureItems: INodeExecutionData[] = [];
|
||||
const returnItems: INodeExecutionData[] = [];
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
const graphApiCredentials = this.getCredentials('graphApi');
|
||||
const graphApiCredentials = this.getCredentials('facebookGraphApi');
|
||||
|
||||
const hostUrl = this.getNodeParameter('hostUrl', itemIndex) as string;
|
||||
const httpRequestMethod = this.getNodeParameter('httpRequestMethod', itemIndex) as string;
|
||||
const graphApiVersion = this.getNodeParameter('graphApiVersion', itemIndex) as string;
|
||||
let graphApiVersion = this.getNodeParameter('graphApiVersion', itemIndex) as string;
|
||||
const node = this.getNodeParameter('node', itemIndex) as string;
|
||||
const edge = this.getNodeParameter('edge', itemIndex) as string;
|
||||
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
|
||||
|
||||
if (graphApiVersion !== '') {
|
||||
graphApiVersion += '/';
|
||||
}
|
||||
|
||||
let uri = `https://${hostUrl}/${graphApiVersion}${node}`;
|
||||
if (edge) {
|
||||
uri = `${uri}/${edge}`;
|
||||
|
@ -315,7 +317,7 @@ export class GraphApi implements INodeType {
|
|||
if (options.queryParameters !== undefined) {
|
||||
const queryParameters = options.queryParameters as IDataObject;
|
||||
|
||||
if (queryParameters.parameter != undefined) {
|
||||
if (queryParameters.parameter !== undefined) {
|
||||
for (const queryParameter of queryParameters.parameter as IDataObject[]) {
|
||||
requestOptions.qs[queryParameter.name as string] = queryParameter.value;
|
||||
}
|
||||
|
@ -379,22 +381,7 @@ export class GraphApi implements INodeType {
|
|||
throw error;
|
||||
}
|
||||
|
||||
let errorItem;
|
||||
if (error.response !== undefined) {
|
||||
// Since this is a Graph API node and we already know the request was
|
||||
// not successful, we'll go straight to the error details.
|
||||
const graphApiErrors = error.response.body?.error ?? {};
|
||||
|
||||
errorItem = {
|
||||
statusCode: error.statusCode,
|
||||
...graphApiErrors,
|
||||
headers: error.response.headers,
|
||||
};
|
||||
} else {
|
||||
// Unknown Graph API response, we'll dump everything in the response item
|
||||
errorItem = error;
|
||||
}
|
||||
failureItems.push({ json: { ...errorItem }});
|
||||
returnItems.push(items[itemIndex]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -404,13 +391,13 @@ export class GraphApi implements INodeType {
|
|||
throw new Error('Response body is not valid JSON.');
|
||||
}
|
||||
|
||||
failureItems.push({json: {message: response}});
|
||||
returnItems.push(items[itemIndex]);
|
||||
continue;
|
||||
}
|
||||
|
||||
successItems.push({json: response});
|
||||
returnItems.push({json: response});
|
||||
}
|
||||
|
||||
return [successItems, failureItems];
|
||||
return [returnItems];
|
||||
}
|
||||
}
|
|
@ -48,13 +48,13 @@
|
|||
"dist/credentials/DriftApi.credentials.js",
|
||||
"dist/credentials/DropboxApi.credentials.js",
|
||||
"dist/credentials/EventbriteApi.credentials.js",
|
||||
"dist/credentials/FacebookGraphApi.credentials.js",
|
||||
"dist/credentials/FreshdeskApi.credentials.js",
|
||||
"dist/credentials/FileMaker.credentials.js",
|
||||
"dist/credentials/FlowApi.credentials.js",
|
||||
"dist/credentials/GithubApi.credentials.js",
|
||||
"dist/credentials/GitlabApi.credentials.js",
|
||||
"dist/credentials/GoogleApi.credentials.js",
|
||||
"dist/credentials/GraphApi.credentials.js",
|
||||
"dist/credentials/GumroadApi.credentials.js",
|
||||
"dist/credentials/HarvestApi.credentials.js",
|
||||
"dist/credentials/HttpBasicAuth.credentials.js",
|
||||
|
@ -155,6 +155,7 @@
|
|||
"dist/nodes/Eventbrite/EventbriteTrigger.node.js",
|
||||
"dist/nodes/ExecuteCommand.node.js",
|
||||
"dist/nodes/ExecuteWorkflow.node.js",
|
||||
"dist/nodes/Facebook/FacebookGraphApi.node.js",
|
||||
"dist/nodes/FileMaker/FileMaker.node.js",
|
||||
"dist/nodes/Freshdesk/Freshdesk.node.js",
|
||||
"dist/nodes/Flow/Flow.node.js",
|
||||
|
@ -167,7 +168,6 @@
|
|||
"dist/nodes/Gitlab/GitlabTrigger.node.js",
|
||||
"dist/nodes/Google/GoogleDrive.node.js",
|
||||
"dist/nodes/Google/GoogleSheets.node.js",
|
||||
"dist/nodes/Facebook/GraphApi.node.js",
|
||||
"dist/nodes/GraphQL/GraphQL.node.js",
|
||||
"dist/nodes/Gumroad/GumroadTrigger.node.js",
|
||||
"dist/nodes/Harvest/Harvest.node.js",
|
||||
|
|
Loading…
Reference in a new issue