N8n fastbill node development

I am devloping an custom node for an Api (FastBill).

Documentation under: FastBill API Documentation

The parameters from the input get an extra = before the inserted value, if i use exprsessions.

Code from the node

	{
				displayName: 'Operation',
				name: 'operation',
				type: 'options',
				noDataExpression: true,
				options: [
					{
						name: 'Get',
						value: 'get',
						description: 'Get a list of contacts',
						action: 'Get a list of contacts',
						routing: {
							request: {
								method: 'POST',
								// Build the Fastbill request body from user-provided filters
								body: '={{ (() => {\n\tconst f = $parameter["filter"] || {};\n\tconst FILTER = {};\n\tif (f.CUSTOMER_ID) FILTER.CUSTOMER_ID = $evaluateExpression(f.CUSTOMER_ID);\n\tif (f.CUSTOMER_NUMBER) FILTER.CUSTOMER_NUMBER = $evaluateExpression(f.CUSTOMER_NUMBER);\n\tif (f.COUNTRY_CODE) FILTER.COUNTRY_CODE = $evaluateExpression(f.COUNTRY_CODE);\n\tif (f.CITY) FILTER.CITY = $evaluateExpression(f.CITY);\n\tif (f.TERM) FILTER.TERM = $evaluateExpression(f.TERM);\n\treturn { SERVICE: "customer.get", FILTER };\n})() }}',
							},
						}
					},
				],
				default: 'get',
			},

Is there an better way for defining the body for apis?

Share the output returned by the last node

{
				displayName: 'Operation',
				name: 'operation',
				type: 'options',
				noDataExpression: true,
				options: [
					{
						name: 'Get',
						value: 'get',
						description: 'Get a list of contacts',
						action: 'Get a list of contacts',
						routing: {
							request: {
								method: 'POST',
								// Build the Fastbill request body from user-provided filters
								body: '={{ (() => {\n\tconst f = $parameter["filter"] || {};\n\tconst FILTER = {};\n\tif (f.CUSTOMER_ID) FILTER.CUSTOMER_ID = $evaluateExpression(f.CUSTOMER_ID);\n\tif (f.CUSTOMER_NUMBER) FILTER.CUSTOMER_NUMBER = $evaluateExpression(f.CUSTOMER_NUMBER);\n\tif (f.COUNTRY_CODE) FILTER.COUNTRY_CODE = $evaluateExpression(f.COUNTRY_CODE);\n\tif (f.CITY) FILTER.CITY = $evaluateExpression(f.CITY);\n\tif (f.TERM) FILTER.TERM = $evaluateExpression(f.TERM);\n\treturn { SERVICE: "customer.get", FILTER };\n})() }}',
							},
						}
					},
				],
				default: 'get',
			},

Information on your n8n setup

  • n8n version: n8n create node latest version

ok got it working:

{
						name: 'Get',
						value: 'get',
						description: 'Get a list of contacts',
						action: 'Get a list of contacts',
						routing: {
							send: {
								type: 'body',
								property: 'SERVICE',
								value:"customer.get"
							},
							request: {
								method: 'POST',
							},
						},
					},

And in the Filter options:

{
						displayName: 'TERM',
						name: 'TERM',
						type: 'string',
						default: '',
						routing: {
							send: {
								type: 'body',
								property: 'FILTER.TERM',
							},
						},
						
					},
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.