Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

INT-441: Add Onfleet nodes to n8n #1

Merged
merged 3 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/nodes-base/credentials/OnfleetApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';

export class OnfleetApi implements ICredentialType {
name = 'onfleetApi';
displayName = 'Onfleet API';
documentationUrl = 'onfleet';
properties = [
{
displayName: 'API Key',
name: 'apiKey',
type: 'string' as NodePropertyTypes,
default: '',
},
];
}
56 changes: 56 additions & 0 deletions packages/nodes-base/nodes/Onfleet/GenericFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
IDataObject,
JsonObject,
NodeApiError
} from 'n8n-workflow';
import {
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IWebhookFunctions,
} from 'n8n-core';

import {
OptionsWithUri,
} from 'request';

export async function onfleetApiRequest(
this: IWebhookFunctions | IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: string,
apikey: string,
resource: string,
body: any = {}, // tslint:disable-line:no-any
qs?: any, // tslint:disable-line:no-any
uri?: string,
headers: IDataObject = {},
option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${apikey}`,
'User-Agent': 'n8n-onfleet',
},
method,
body,
qs,
uri: uri || `https://onfleet.com/api/v2/${resource}`,
json: true,
};
try {
//@ts-ignore
return await this.helpers.request(options);
} catch (error) {
const apiError = error as IDataObject;
const { message: messageError } = apiError.error as IDataObject;
if (messageError) {
const { message = '', cause = '' } = messageError as IDataObject;
if (message && cause) {
apiError.message = `${message}: ${cause}`;
} else {
apiError.message = message;
}
throw new NodeApiError(this.getNode(), apiError as JsonObject);
}
throw new NodeApiError(this.getNode(), apiError as JsonObject);
}
}
Loading