Skip to content
Merged
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: 14 additions & 4 deletions nodes/Apify/resources/genericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type IApiRequestOptions = IRequestOptions & { uri?: string };

/**
* Make an API request to Apify
*
*/
export async function apiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
Expand All @@ -29,15 +28,21 @@ export async function apiRequest(
const query = qs || {};
const endpoint = `https://api.apify.com${uri}`;

const headers: Record<string, string> = {
'x-apify-integration-platform': 'n8n',
};

if (isUsedAsAiTool(this.getNode().type)) {
headers['x-apify-integration-ai-tool'] = 'true';
}

const options: IRequestOptions = {
json: true,
...rest,
method,
qs: query,
url: endpoint,
headers: {
'x-apify-integration-platform': 'n8n',
},
headers,
};

if (method === 'GET') {
Expand Down Expand Up @@ -256,3 +261,8 @@ export function customBodyParser(input: string | object) {
return input;
}
}

export function isUsedAsAiTool(nodeType: string): boolean {
const parts = nodeType.split('.');
return parts[parts.length - 1] === 'apifyTool';
}
Loading