Skip to content

Commit

Permalink
Updated api template node (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: Omri Attoun <[email protected]>
  • Loading branch information
omrijoyous and omri10 authored Oct 26, 2023
1 parent ddd0fbf commit 23a3d9d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NodeOperationError } from 'n8n-workflow';

import {
apiTemplateIoApiRequest,
apiTemplateIoApiRequestV2,
downloadImage,
loadResource,
validateJSON,
Expand Down Expand Up @@ -516,7 +517,7 @@ export class ApiTemplateIo implements INodeType {
}
}

responseData = await apiTemplateIoApiRequest.call(
responseData = await apiTemplateIoApiRequestV2.call(
this,
'POST',
'/create',
Expand Down
44 changes: 44 additions & 0 deletions packages/nodes-base/nodes/ApiTemplateIo/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,47 @@ export async function downloadImage(this: IExecuteFunctions, url: string) {
encoding: null,
});
}

export async function apiTemplateIoApiRequestV2(
this: IExecuteFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
qs = {},
body = {},
) {
const options: OptionsWithUri = {
headers: {
'user-agent': 'n8n',
Accept: 'application/json',
},
uri: `https://rest.apitemplate.io/v2${endpoint}`,
method,
qs,
body,
followRedirect: true,
followAllRedirects: true,
json: true,
};

if (!Object.keys(body).length) {
delete options.body;
}

if (!Object.keys(qs).length) {
delete options.qs;
}

try {
const response = await this.helpers.requestWithAuthentication.call(
this,
'apiTemplateIoApi',
options,
);
if (response.status === 'error') {
throw new NodeApiError(this.getNode(), response.message as JsonObject);
}
return response;
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}

0 comments on commit 23a3d9d

Please sign in to comment.