first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,251 @@
import type { INodeProperties } from 'n8n-workflow';
import { getCustomerOptionalFields, getSearchFilters } from './GenericFunctions';
export const customerOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['customer'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new customer',
action: 'Create a customer',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a customer',
action: 'Delete a customer',
},
{
name: 'Get',
value: 'get',
description: 'Get a customer',
action: 'Get a customer',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many customers',
action: 'Get many customers',
},
{
name: 'Update',
value: 'update',
description: 'Update a customer',
action: 'Update a customer',
},
],
default: 'create',
},
];
export const customerFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* customer:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Email',
name: 'email',
type: 'string',
placeholder: 'name@email.com',
required: true,
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['create'],
},
},
description: 'Email address of the user to create',
},
{
displayName: 'First Name',
name: 'firstname',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['create'],
},
},
description: 'First name of the user to create',
},
{
displayName: 'Last Name',
name: 'lastname',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['create'],
},
},
description: 'Last name of the user to create',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['customer'],
operation: ['create'],
},
},
options: [...getCustomerOptionalFields()],
},
/* -------------------------------------------------------------------------- */
/* customer:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Customer ID',
name: 'customerId',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['update'],
},
},
description: 'ID of the customer to update',
},
{
displayName: 'Email',
name: 'email',
type: 'string',
placeholder: 'name@email.com',
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['update'],
},
},
},
{
displayName: 'First Name',
name: 'firstName',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['update'],
},
},
},
{
displayName: 'Last Name',
name: 'lastName',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['update'],
},
},
},
{
displayName: 'Website Name or ID',
name: 'website_id',
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
displayOptions: {
show: {
resource: ['customer'],
operation: ['update'],
},
},
typeOptions: {
loadOptionsMethod: 'getWebsites',
},
default: '',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['customer'],
operation: ['update'],
},
},
options: [...getCustomerOptionalFields()],
},
/* -------------------------------------------------------------------------- */
/* customer:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Customer ID',
name: 'customerId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['customer'],
operation: ['delete', 'get'],
},
},
},
/* -------------------------------------------------------------------------- */
/* customer:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['customer'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['customer'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 5,
description: 'Max number of results to return',
},
...getSearchFilters('customer', 'getSystemAttributes', 'getSystemAttributes'),
];
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,43 @@
import type { INodeProperties } from 'n8n-workflow';
export const invoiceOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['invoice'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create an invoice',
action: 'Create an invoice',
},
],
default: 'create',
},
];
export const invoiceFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* invoice:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Order ID',
name: 'orderId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['invoice'],
operation: ['create'],
},
},
},
];
@@ -0,0 +1,18 @@
{
"node": "n8n-nodes-base.magento2",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Sales"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/magento2/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.magento2/"
}
]
}
}
@@ -0,0 +1,815 @@
import { capitalCase } from 'change-case';
import type {
IExecuteFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionTypes, NodeApiError } from 'n8n-workflow';
import { customerFields, customerOperations } from './CustomerDescription';
import {
adjustAddresses,
getFilterQuery,
getOrderFields,
getProductAttributes,
magentoApiRequest,
magentoApiRequestAllItems,
sort,
validateJSON,
} from './GenericFunctions';
import { invoiceFields, invoiceOperations } from './InvoiceDescription';
import { orderFields, orderOperations } from './OrderDescription';
import { productFields, productOperations } from './ProductDescription';
import type {
CustomAttribute,
CustomerAttributeMetadata,
Filter,
NewCustomer,
NewProduct,
Search,
} from './types';
export class Magento2 implements INodeType {
description: INodeTypeDescription = {
displayName: 'Magento 2',
name: 'magento2',
icon: 'file:magento.svg',
group: ['input'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Magento API',
defaults: {
name: 'Magento 2',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'magento2Api',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Customer',
value: 'customer',
},
{
name: 'Invoice',
value: 'invoice',
},
{
name: 'Order',
value: 'order',
},
{
name: 'Product',
value: 'product',
},
],
default: 'customer',
},
...customerOperations,
...customerFields,
...invoiceOperations,
...invoiceFields,
...orderOperations,
...orderFields,
...productOperations,
...productFields,
],
};
methods = {
loadOptions: {
async getCountries(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/directorycountries
const countries = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/directory/countries',
);
const returnData: INodePropertyOptions[] = [];
for (const country of countries) {
returnData.push({
name: country.full_name_english,
value: country.id,
});
}
returnData.sort(sort);
return returnData;
},
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/customerGroupsdefault#operation/customerGroupManagementV1GetDefaultGroupGet
const group = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/customerGroups/default',
);
const returnData: INodePropertyOptions[] = [];
returnData.push({
name: group.code,
value: group.id,
});
returnData.sort(sort);
return returnData;
},
async getStores(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/storestoreConfigs
const stores = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/store/storeConfigs',
);
const returnData: INodePropertyOptions[] = [];
for (const store of stores) {
returnData.push({
name: store.base_url,
value: store.id,
});
}
returnData.sort(sort);
return returnData;
},
async getWebsites(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/storewebsites
const websites = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/store/websites',
);
const returnData: INodePropertyOptions[] = [];
for (const website of websites) {
returnData.push({
name: website.name,
value: website.id,
});
}
returnData.sort(sort);
return returnData;
},
async getCustomAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/attributeMetadatacustomer#operation/customerCustomerMetadataV1GetAllAttributesMetadataGet
const resource = this.getCurrentNodeParameter('resource') as string;
const attributes = (await magentoApiRequest.call(
this,
'GET',
`/rest/default/V1/attributeMetadata/${resource}`,
)) as CustomerAttributeMetadata[];
const returnData: INodePropertyOptions[] = [];
for (const attribute of attributes) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
if (attribute.system === false && attribute.frontend_label !== '') {
returnData.push({
name: attribute.frontend_label as string,
value: attribute.attribute_code as string,
});
}
}
returnData.sort(sort);
return returnData;
},
async getSystemAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/attributeMetadatacustomer#operation/customerCustomerMetadataV1GetAllAttributesMetadataGet
const resource = this.getCurrentNodeParameter('resource') as string;
const attributes = (await magentoApiRequest.call(
this,
'GET',
`/rest/default/V1/attributeMetadata/${resource}`,
)) as CustomerAttributeMetadata[];
const returnData: INodePropertyOptions[] = [];
for (const attribute of attributes) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
if (attribute.system === true && attribute.frontend_label !== null) {
returnData.push({
name: attribute.frontend_label as string,
value: attribute.attribute_code as string,
});
}
}
returnData.sort(sort);
return returnData;
},
async getProductTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/productslinkstypes
const types = (await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/products/types',
)) as IDataObject[];
const returnData: INodePropertyOptions[] = [];
for (const type of types) {
returnData.push({
name: type.label as string,
value: type.name as string,
});
}
returnData.sort(sort);
return returnData;
},
async getCategories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/categories#operation/catalogCategoryManagementV1GetTreeGet
const { items: categories } = (await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/categories/list',
{},
{
search_criteria: {
filter_groups: [
{
filters: [
{
field: 'is_active',
condition_type: 'eq',
value: 1,
},
],
},
],
},
},
)) as { items: IDataObject[] };
const returnData: INodePropertyOptions[] = [];
for (const category of categories) {
returnData.push({
name: category.name as string,
value: category.id as string,
});
}
returnData.sort(sort);
return returnData;
},
async getAttributeSets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
//https://magento.redoc.ly/2.3.7-admin/tag/productsattribute-setssetslist#operation/catalogAttributeSetRepositoryV1GetListGet
const { items: attributeSets } = (await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/products/attribute-sets/sets/list',
{},
{
search_criteria: 0,
},
)) as { items: IDataObject[] };
const returnData: INodePropertyOptions[] = [];
for (const attributeSet of attributeSets) {
returnData.push({
name: attributeSet.attribute_set_name as string,
value: attributeSet.attribute_set_id as string,
});
}
returnData.sort(sort);
return returnData;
},
async getFilterableCustomerAttributes(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
return await getProductAttributes.call(this, (attribute) => attribute.is_filterable);
},
async getProductAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
return await getProductAttributes.call(this);
},
// async getProductAttributesFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
// return getProductAttributes.call(this, undefined, { name: '*', value: '*', description: 'All properties' });
// },
async getFilterableProductAttributes(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
return await getProductAttributes.call(
this,
(attribute) => attribute.is_searchable === '1',
);
},
async getSortableProductAttributes(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
return await getProductAttributes.call(this, (attribute) => attribute.used_for_sort_by);
},
async getOrderAttributes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
return getOrderFields()
.map((field) => ({ name: capitalCase(field), value: field }))
.sort(sort);
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
let responseData;
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
for (let i = 0; i < length; i++) {
try {
if (resource === 'customer') {
if (operation === 'create') {
// https://magento.redoc.ly/2.3.7-admin/tag/customerscustomerId#operation/customerCustomerRepositoryV1SavePut
const email = this.getNodeParameter('email', i) as string;
const firstname = this.getNodeParameter('firstname', i) as string;
const lastname = this.getNodeParameter('lastname', i) as string;
const { addresses, customAttributes, password, ...rest } = this.getNodeParameter(
'additionalFields',
i,
) as {
addresses: {
address: [
{
street: string;
},
];
};
customAttributes: {
customAttribute: CustomAttribute[];
};
password: string;
};
const body: NewCustomer = {
customer: {
email,
firstname,
lastname,
},
};
body.customer!.addresses = adjustAddresses(addresses?.address || []);
body.customer!.custom_attributes = customAttributes?.customAttribute || [];
body.customer!.extension_attributes = [
'amazon_id',
'is_subscribed',
'vertex_customer_code',
'vertex_customer_country',
].reduce((obj, value: string): any => {
if ((rest as IDataObject).hasOwnProperty(value)) {
const data = Object.assign(obj, { [value]: (rest as IDataObject)[value] });
delete (rest as IDataObject)[value];
return data;
} else {
return obj;
}
}, {});
if (password) {
body.password = password;
}
Object.assign(body.customer!, rest);
responseData = await magentoApiRequest.call(this, 'POST', '/rest/V1/customers', body);
}
if (operation === 'delete') {
//https://magento.redoc.ly/2.3.7-admin/tag/customerscustomerId#operation/customerCustomerRepositoryV1SavePut
const customerId = this.getNodeParameter('customerId', i) as string;
responseData = await magentoApiRequest.call(
this,
'DELETE',
`/rest/default/V1/customers/${customerId}`,
);
responseData = { success: true };
}
if (operation === 'get') {
//https://magento.redoc.ly/2.3.7-admin/tag/customerscustomerId#operation/customerCustomerRepositoryV1GetByIdGet
const customerId = this.getNodeParameter('customerId', i) as string;
responseData = await magentoApiRequest.call(
this,
'GET',
`/rest/default/V1/customers/${customerId}`,
);
}
if (operation === 'getAll') {
//https://magento.redoc.ly/2.3.7-admin/tag/customerssearch
const filterType = this.getNodeParameter('filterType', i) as string;
const sortOption = this.getNodeParameter('options.sort', i, {}) as {
sort: [{ direction: string; field: string }];
};
const returnAll = this.getNodeParameter('returnAll', 0);
let qs: Search = {};
if (filterType === 'manual') {
const filters = this.getNodeParameter('filters', i) as { conditions: Filter[] };
const matchType = this.getNodeParameter('matchType', i) as string;
qs = getFilterQuery(Object.assign(filters, { matchType }, sortOption));
} else if (filterType === 'json') {
const filterJson = this.getNodeParameter('filterJson', i) as string;
if (validateJSON(filterJson) !== undefined) {
qs = JSON.parse(filterJson);
} else {
throw new NodeApiError(this.getNode(), {
message: 'Filter (JSON) must be a valid json',
});
}
} else {
qs = {
search_criteria: {},
};
if (Object.keys(sortOption).length !== 0) {
qs.search_criteria = {
sort_orders: sortOption.sort,
};
}
}
if (returnAll) {
qs.search_criteria!.page_size = 100;
responseData = await magentoApiRequestAllItems.call(
this,
'items',
'GET',
'/rest/default/V1/customers/search',
{},
qs as unknown as IDataObject,
);
} else {
const limit = this.getNodeParameter('limit', 0);
qs.search_criteria!.page_size = limit;
responseData = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/customers/search',
{},
qs as unknown as IDataObject,
);
responseData = responseData.items;
}
}
if (operation === 'update') {
//https://magento.redoc.ly/2.3.7-admin/tag/customerscustomerId#operation/customerCustomerRepositoryV1SavePut
const customerId = this.getNodeParameter('customerId', i) as string;
const firstName = this.getNodeParameter('firstName', i) as string;
const lastName = this.getNodeParameter('lastName', i) as string;
const email = this.getNodeParameter('email', i) as string;
const { addresses, customAttributes, password, ...rest } = this.getNodeParameter(
'updateFields',
i,
) as {
addresses: {
address: [
{
street: string;
},
];
};
customAttributes: {
customAttribute: CustomAttribute[];
};
password: string;
};
const body: NewCustomer = {
customer: {
email,
firstname: firstName,
lastname: lastName,
id: parseInt(customerId, 10),
website_id: 0,
},
};
body.customer!.addresses = adjustAddresses(addresses?.address || []);
body.customer!.custom_attributes = customAttributes?.customAttribute || [];
body.customer!.extension_attributes = [
'amazon_id',
'is_subscribed',
'vertex_customer_code',
'vertex_customer_country',
].reduce((obj, value: string): any => {
if ((rest as IDataObject).hasOwnProperty(value)) {
const data = Object.assign(obj, { [value]: (rest as IDataObject)[value] });
delete (rest as IDataObject)[value];
return data;
} else {
return obj;
}
}, {});
if (password) {
body.password = password;
}
Object.assign(body.customer!, rest);
responseData = await magentoApiRequest.call(
this,
'PUT',
`/rest/V1/customers/${customerId}`,
body,
);
}
}
if (resource === 'invoice') {
if (operation === 'create') {
///https://magento.redoc.ly/2.3.7-admin/tag/orderorderIdinvoice
const orderId = this.getNodeParameter('orderId', i) as string;
responseData = await magentoApiRequest.call(
this,
'POST',
`/rest/default/V1/order/${orderId}/invoice`,
);
responseData = { success: true };
}
}
if (resource === 'order') {
if (operation === 'cancel') {
//https://magento.redoc.ly/2.3.7-admin/tag/ordersidcancel
const orderId = this.getNodeParameter('orderId', i) as string;
responseData = await magentoApiRequest.call(
this,
'POST',
`/rest/default/V1/orders/${orderId}/cancel`,
);
responseData = { success: true };
}
if (operation === 'get') {
//https://magento.redoc.ly/2.3.7-admin/tag/ordersid#operation/salesOrderRepositoryV1GetGet
const orderId = this.getNodeParameter('orderId', i) as string;
responseData = await magentoApiRequest.call(
this,
'GET',
`/rest/default/V1/orders/${orderId}`,
);
}
if (operation === 'ship') {
///https://magento.redoc.ly/2.3.7-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost
const orderId = this.getNodeParameter('orderId', i) as string;
responseData = await magentoApiRequest.call(
this,
'POST',
`/rest/default/V1/order/${orderId}/ship`,
);
responseData = { success: true };
}
if (operation === 'getAll') {
//https://magento.redoc.ly/2.3.7-admin/tag/orders#operation/salesOrderRepositoryV1GetListGet
const filterType = this.getNodeParameter('filterType', i) as string;
const sortOption = this.getNodeParameter('options.sort', i, {}) as {
sort: [{ direction: string; field: string }];
};
const returnAll = this.getNodeParameter('returnAll', 0);
let qs: Search = {};
if (filterType === 'manual') {
const filters = this.getNodeParameter('filters', i) as { conditions: Filter[] };
const matchType = this.getNodeParameter('matchType', i) as string;
qs = getFilterQuery(Object.assign(filters, { matchType }, sortOption));
} else if (filterType === 'json') {
const filterJson = this.getNodeParameter('filterJson', i) as string;
if (validateJSON(filterJson) !== undefined) {
qs = JSON.parse(filterJson);
} else {
throw new NodeApiError(this.getNode(), {
message: 'Filter (JSON) must be a valid json',
});
}
} else {
qs = {
search_criteria: {},
};
if (Object.keys(sortOption).length !== 0) {
qs.search_criteria = {
sort_orders: sortOption.sort,
};
}
}
if (returnAll) {
qs.search_criteria!.page_size = 100;
responseData = await magentoApiRequestAllItems.call(
this,
'items',
'GET',
'/rest/default/V1/orders',
{},
qs as unknown as IDataObject,
);
} else {
const limit = this.getNodeParameter('limit', 0);
qs.search_criteria!.page_size = limit;
responseData = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/orders',
{},
qs as unknown as IDataObject,
);
responseData = responseData.items;
}
}
}
if (resource === 'product') {
if (operation === 'create') {
// https://magento.redoc.ly/2.3.7-admin/tag/products#operation/catalogProductRepositoryV1SavePost
const sku = this.getNodeParameter('sku', i) as string;
const name = this.getNodeParameter('name', i) as string;
const attributeSetId = this.getNodeParameter('attributeSetId', i) as string;
const price = this.getNodeParameter('price', i) as number;
const {
customAttributes,
category: _category,
...rest
} = this.getNodeParameter('additionalFields', i) as {
customAttributes: {
customAttribute: CustomAttribute[];
};
category: string;
};
const body: NewProduct = {
product: {
sku,
name,
attribute_set_id: parseInt(attributeSetId, 10),
price,
},
};
body.product!.custom_attributes = customAttributes?.customAttribute || [];
Object.assign(body.product!, rest);
responseData = await magentoApiRequest.call(
this,
'POST',
'/rest/default/V1/products',
body,
);
}
if (operation === 'delete') {
//https://magento.redoc.ly/2.3.7-admin/tag/productssku#operation/catalogProductRepositoryV1DeleteByIdDelete
const sku = this.getNodeParameter('sku', i) as string;
responseData = await magentoApiRequest.call(
this,
'DELETE',
`/rest/default/V1/products/${sku}`,
);
responseData = { success: true };
}
if (operation === 'get') {
//https://magento.redoc.ly/2.3.7-admin/tag/productssku#operation/catalogProductRepositoryV1GetGet
const sku = this.getNodeParameter('sku', i) as string;
responseData = await magentoApiRequest.call(
this,
'GET',
`/rest/default/V1/products/${sku}`,
);
}
if (operation === 'getAll') {
//https://magento.redoc.ly/2.3.7-admin/tag/customerssearch
const filterType = this.getNodeParameter('filterType', i) as string;
const sortOption = this.getNodeParameter('options.sort', i, {}) as {
sort: [{ direction: string; field: string }];
};
const returnAll = this.getNodeParameter('returnAll', 0);
let qs: Search = {};
if (filterType === 'manual') {
const filters = this.getNodeParameter('filters', i) as { conditions: Filter[] };
const matchType = this.getNodeParameter('matchType', i) as string;
qs = getFilterQuery(Object.assign(filters, { matchType }, sortOption));
} else if (filterType === 'json') {
const filterJson = this.getNodeParameter('filterJson', i) as string;
if (validateJSON(filterJson) !== undefined) {
qs = JSON.parse(filterJson);
} else {
throw new NodeApiError(this.getNode(), {
message: 'Filter (JSON) must be a valid json',
});
}
} else {
qs = {
search_criteria: {},
};
if (Object.keys(sortOption).length !== 0) {
qs.search_criteria = {
sort_orders: sortOption.sort,
};
}
}
if (returnAll) {
qs.search_criteria!.page_size = 100;
responseData = await magentoApiRequestAllItems.call(
this,
'items',
'GET',
'/rest/default/V1/products',
{},
qs as unknown as IDataObject,
);
} else {
const limit = this.getNodeParameter('limit', 0);
qs.search_criteria!.page_size = limit;
responseData = await magentoApiRequest.call(
this,
'GET',
'/rest/default/V1/products',
{},
qs as unknown as IDataObject,
);
responseData = responseData.items;
}
}
if (operation === 'update') {
//https://magento.redoc.ly/2.3.7-admin/tag/productssku#operation/catalogProductRepositoryV1SavePut
const sku = this.getNodeParameter('sku', i) as string;
const { customAttributes, ...rest } = this.getNodeParameter('updateFields', i) as {
customAttributes: {
customAttribute: CustomAttribute[];
};
};
if (!Object.keys(rest).length) {
throw new NodeApiError(this.getNode(), {
message: 'At least one parameter has to be updated',
});
}
const body: NewProduct = {
product: {
sku,
},
};
body.product!.custom_attributes = customAttributes?.customAttribute || [];
Object.assign(body.product!, rest);
responseData = await magentoApiRequest.call(
this,
'PUT',
`/rest/default/V1/products/${sku}`,
body,
);
}
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as IDataObject[]),
{ itemData: { item: i } },
);
returnData.push(...executionData);
} catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ error: error.message }),
{ itemData: { item: i } },
);
returnData.push(...executionErrorData);
continue;
}
throw error;
}
}
return [returnData];
}
}
@@ -0,0 +1,99 @@
import type { INodeProperties } from 'n8n-workflow';
import { getSearchFilters } from './GenericFunctions';
export const orderOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['order'],
},
},
options: [
{
name: 'Cancel',
value: 'cancel',
description: 'Cancel an order',
action: 'Cancel an order',
},
{
name: 'Get',
value: 'get',
description: 'Get an order',
action: 'Get an order',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many orders',
action: 'Get many orders',
},
{
name: 'Ship',
value: 'ship',
description: 'Ship an order',
action: 'Ship an order',
},
],
default: 'cancel',
},
];
export const orderFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* order:cancel */
/* -------------------------------------------------------------------------- */
{
displayName: 'Order ID',
name: 'orderId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['order'],
operation: ['cancel', 'get', 'ship'],
},
},
},
/* -------------------------------------------------------------------------- */
/* order:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['order'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['order'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 5,
description: 'Max number of results to return',
},
...getSearchFilters('order', 'getOrderAttributes', 'getOrderAttributes'),
];
@@ -0,0 +1,199 @@
import type { INodeProperties } from 'n8n-workflow';
import { getProductOptionalFields, getSearchFilters } from './GenericFunctions';
export const productOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['product'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a product',
action: 'Create a product',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a product',
action: 'Delete a product',
},
{
name: 'Get',
value: 'get',
description: 'Get a product',
action: 'Get a product',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get many products',
action: 'Get many products',
},
{
name: 'Update',
value: 'update',
description: 'Update a product',
action: 'Update a product',
},
],
default: 'create',
},
];
export const productFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* product:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'SKU',
name: 'sku',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: ['product'],
operation: ['create', 'update'],
},
},
description: 'Stock-keeping unit of the product',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['product'],
operation: ['create'],
},
},
default: '',
},
{
displayName: 'Attribute Set Name or ID',
name: 'attributeSetId',
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
displayOptions: {
show: {
resource: ['product'],
operation: ['create'],
},
},
typeOptions: {
loadOptionsMethod: 'getAttributeSets',
},
default: '',
},
{
displayName: 'Price',
name: 'price',
type: 'number',
displayOptions: {
show: {
resource: ['product'],
operation: ['create'],
},
},
default: 0,
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['product'],
operation: ['create'],
},
},
options: [...getProductOptionalFields()],
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['product'],
operation: ['update'],
},
},
options: [...getProductOptionalFields()],
},
/* -------------------------------------------------------------------------- */
/* product:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'SKU',
name: 'sku',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: ['product'],
operation: ['delete', 'get'],
},
},
description: 'Stock-keeping unit of the product',
},
/* -------------------------------------------------------------------------- */
/* product:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['product'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['product'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 5,
description: 'Max number of results to return',
},
...getSearchFilters(
'product',
//'getProductAttributesFields',
'getFilterableProductAttributes',
'getSortableProductAttributes',
),
];
@@ -0,0 +1,215 @@
{
"type": "object",
"properties": {
"attribute_set_id": {
"type": "integer"
},
"created_at": {
"type": "string"
},
"custom_attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"attribute_code": {
"type": "string"
}
}
}
},
"extension_attributes": {
"type": "object",
"properties": {
"stock_item": {
"type": "object",
"properties": {
"backorders": {
"type": "integer"
},
"enable_qty_increments": {
"type": "boolean"
},
"is_decimal_divided": {
"type": "boolean"
},
"is_in_stock": {
"type": "boolean"
},
"is_qty_decimal": {
"type": "boolean"
},
"item_id": {
"type": "integer"
},
"manage_stock": {
"type": "boolean"
},
"max_sale_qty": {
"type": "integer"
},
"min_qty": {
"type": "integer"
},
"min_sale_qty": {
"type": "integer"
},
"notify_stock_qty": {
"type": "integer"
},
"product_id": {
"type": "integer"
},
"qty": {
"type": "integer"
},
"qty_increments": {
"type": "integer"
},
"show_default_notification_message": {
"type": "boolean"
},
"stock_id": {
"type": "integer"
},
"stock_status_changed_auto": {
"type": "integer"
},
"use_config_backorders": {
"type": "boolean"
},
"use_config_enable_qty_inc": {
"type": "boolean"
},
"use_config_manage_stock": {
"type": "boolean"
},
"use_config_max_sale_qty": {
"type": "boolean"
},
"use_config_min_qty": {
"type": "boolean"
},
"use_config_min_sale_qty": {
"type": "integer"
},
"use_config_notify_stock_qty": {
"type": "boolean"
},
"use_config_qty_increments": {
"type": "boolean"
}
}
},
"website_ids": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"id": {
"type": "integer"
},
"media_gallery_entries": {
"type": "array",
"items": {
"type": "object",
"properties": {
"disabled": {
"type": "boolean"
},
"file": {
"type": "string"
},
"id": {
"type": "integer"
},
"media_type": {
"type": "string"
},
"position": {
"type": "integer"
},
"types": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"name": {
"type": "string"
},
"product_links": {
"type": "array",
"items": {
"type": "object",
"properties": {
"link_type": {
"type": "string"
},
"linked_product_sku": {
"type": "string"
},
"linked_product_type": {
"type": "string"
},
"position": {
"type": "integer"
},
"sku": {
"type": "string"
}
}
}
},
"sku": {
"type": "string"
},
"status": {
"type": "integer"
},
"tier_prices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"customer_group_id": {
"type": "integer"
},
"extension_attributes": {
"type": "object",
"properties": {
"percentage_value": {
"type": "integer"
},
"website_id": {
"type": "integer"
}
}
},
"qty": {
"type": "integer"
},
"value": {
"type": "number"
}
}
}
},
"type_id": {
"type": "string"
},
"updated_at": {
"type": "string"
},
"visibility": {
"type": "integer"
}
},
"version": 1
}
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="303" preserveAspectRatio="xMidYMid"><path fill="#EC6737" d="M144.852 90.67v172.192l-16.933 10.349-16.946-10.404V90.803l-43.878 27.016v147.255l60.824 37.217 61.339-37.482V117.725zM127.919 0 0 77.502v147.274l33.223 19.572V97.06l94.722-57.596 94.81 57.512.391.223-.042 146.929L256 224.776V77.502z"/></svg>

After

Width:  |  Height:  |  Size: 362 B

+192
View File
@@ -0,0 +1,192 @@
import type { IDataObject } from 'n8n-workflow';
export interface NewCustomer {
customer?: Customer;
password?: string;
redirectUrl?: string;
}
export interface Customer {
id?: number;
group_id?: number;
default_billing?: string;
default_shipping?: string;
confirmation?: string;
created_at?: string;
updated_at?: string;
created_in?: string;
dob?: string;
email?: string;
firstname?: string;
lastname?: string;
middlename?: string;
prefix?: string;
suffix?: string;
gender?: number;
store_id?: number;
taxvat?: string;
website_id?: number;
addresses?: Address[];
disable_auto_group_change?: number;
extension_attributes?: CustomerExtensionAttributes;
custom_attributes?: CustomAttribute[];
}
export interface Address {
id?: number;
customer_id?: number;
region?: Region;
region_id?: number;
country_id?: string;
street?: string[];
company?: string;
telephone?: string;
fax?: string;
postcode?: string;
city?: string;
firstname?: string;
lastname?: string;
middlename?: string;
prefix?: string;
suffix?: string;
vat_id?: string;
default_shipping?: boolean;
default_billing?: boolean;
extension_attributes?: AddressExtensionAttributes;
custom_attributes?: CustomAttribute[];
}
export interface CustomAttribute {
attribute_code?: string;
value?: string;
}
export interface AddressExtensionAttributes {
amazon_id?: string;
is_subscribed?: boolean;
vertex_customer_role?: string;
vertex_customer_country?: string;
}
export interface Region {
region_code?: string;
region?: string;
region_id?: number;
extension_attributes?: AddressExtensionAttributes;
}
export interface CustomerExtensionAttributes {
company_attributes?: CompanyAttributes;
is_subscribed?: boolean;
amazon_id?: string;
vertex_customer_code?: string;
vertex_customer_country?: string;
}
export interface CompanyAttributes {
customer_id?: number;
company_id?: number;
job_title?: string;
status?: number;
telephone?: string;
extension_attributes?: AddressExtensionAttributes;
}
export interface CustomerAttributeMetadata {
frontend_input?: string;
input_filter?: string;
store_label?: string;
validation_rules?: ValidationRule[];
multiline_count?: number;
visible?: boolean;
required?: boolean;
data_model?: string;
options?: CustomerAttributeMetadataOption[];
frontend_class?: string;
user_defined?: boolean;
sort_order?: number;
frontend_label?: string;
note?: string;
system?: boolean;
backend_type?: string;
is_used_in_grid?: boolean;
is_visible_in_grid?: boolean;
is_filterable_in_grid?: boolean;
is_searchable_in_grid?: boolean;
attribute_code?: string;
}
export interface CustomerAttributeMetadataOption {
label?: string;
value?: string;
options?: IDataObject[];
}
export interface ValidationRule {
name?: string;
value?: string;
}
export interface Search {
search_criteria?: SearchCriteria;
total_count?: number;
}
export interface SearchCriteria {
filter_groups?: FilterGroup[];
sort_orders?: SortOrder[];
page_size?: number;
current_page?: number;
}
export interface FilterGroup {
filters?: Filter[];
}
export interface Filter {
field?: string;
value?: string;
condition_type?: string;
}
export interface SortOrder {
field?: string;
direction?: string;
}
export interface NewProduct {
product?: Product;
saveOptions?: boolean;
}
export interface Product {
id?: number;
sku?: string;
name?: string;
attribute_set_id?: number;
price?: number;
status?: number;
visibility?: number;
type_id?: string;
created_at?: string;
updated_at?: string;
weight?: number;
extension_attributes?: {
category_links?: [
{
category_id?: string;
},
];
};
custom_attributes?: CustomAttribute[];
}
export interface ProductAttribute {
is_filterable_in_search: boolean;
default_frontend_label: string;
attribute_id: string;
is_filterable: boolean;
used_for_sort_by: boolean;
is_searchable: string;
attribute_code: string;
}