hello guys. I’m new to javascript so thanks for your patience. I have the following js code that i want to write in a custom function in n8n.
const ewelink = require('ewelink-api');
const connection = new ewelink({
email: '[email protected]',
password: '****************',
region: '**',
});
(async () => {
const device = await connection.getDevice('1111111111');
})();
this function returns the following json object if executed from a shell with console.log output
{
_id: 'sdfsdfsdfsdfsdfsdf',
family: { id: 'sdfsdfsdfsdfsdf', index: 0 },
group: '',
online: true,
groups: [],
devGroups: [],
relational: [],
deviceid: '111111111',
name: 'test',
type: '10',
apikey: 'sdfsdfsdfsdfsdfsdfsdf',
extra:
{ _id: 'sdfsdfsdfsdfsdf',
apikey: 'sdfsdfsdfsdfsdf',
extra:
{ uiid: '15',
description: 'WO1882004',
brandId: 'sdfsdfsdfsdf',
apmac: 'zzzzzzzzzzzz',
mac: 'zzzzzzzzzzzzzzzzzzzz',
ui: 'sdfsdfsdfsdfsdf',
modelInfo: 'zzzzzzzzzzzzzzzzzz',
model: 'rghtghfdghfgh',
manufacturer: 'wdfsdfsdfsdf',
staMac: '123123123123',
chipid: 'ergergerg' },
country: 'cv',
expiredAt: '2023-11-19T00:00:00.000Z',
deviceid: '1111111111',
createdAt: '2018-11-20T07:27:42.501Z' },
settings:
{ opsNotify: 0,
opsHistory: 1,
alarmNotify: 1,
wxAlarmNotify: 0,
wxOpsNotify: 0,
wxDoorbellNotify: 0,
appDoorbellNotify: 1 },
createdAt: '2021-01-02T08:55:37.643Z',
shareUsersInfo:
[ { family: [Object],
apikey: 'yjtyjtyjtyjtyjtyjty',
permit: 15,
shareDate: '2021-01-02T08:56:28.981Z',
comment: '' } ],
__v: 0,
onlineTime: '2021-01-16T16:24:35.028Z',
params:
{ version: 8,
sledOnline: 'on',
init: 1,
switch: 'off',
fwVersion: '3.4.1',
rssi: -74,
staMac: 'sdfsdfsdf',
startup: 'stay',
pulse: 'off',
pulseWidth: 500,
deviceType: 'temperature',
sensorType: 'AM2301',
currentHumidity: '50',
currentTemperature: '38.3',
mainSwitch: 'on',
targets: [ [Object], [Object] ] },
ip: '1.1.1.1',
location: '',
offlineTime: '2021-01-16T16:24:22.297Z',
sharedBy:
{ clientInfo:
{ model: 'Redmi Note 5_sdm636',
os: 'Android',
imei: 'werwewfewe',
romVersion: '9',
appVersion: '4.8.0' },
_id: 'dfgdfgdfgdfg',
email: '[email protected]',
password:
'fgdfdfgdfgdfgdfgdfgdfgdfgdfg',
appId: 'dfgdfgdfgdfgdfgdfg',
countryCode: '+44',
accountInfo: { level: 10 },
apikey: 'dfgdfgdfgdfgdfgdfgdfg',
createdAt: '2021-01-02T08:45:43.237Z',
__v: 0,
language: 'en',
lang: 'en',
extraPush: { dfgdfgdfgdfgdfgdfgdfgdfg: [Object] },
extra:
{ lastEmailAdAt: '2021-01-02T08:45:45.617Z', ipCountry: 'FF' },
isAccepEmailAd: true,
currentFamilyId: 'DFGDFGDFGDFGDFG',
appInfos: [ [Object] ],
online: false,
onlineTime: '2021-01-16T17:05:04.245Z',
ip: '1.1.1.1',
location: '',
offlineTime: '2021-01-16T17:05:19.317Z' },
deviceUrl:
'https://eu-api.coolkit.cc/api/detail/COCOCOCOOC.html',
brandName: 'Sonoff',
productModel: 'TH16',
uiid: '15'
}
my need is to be able to execute it with n8n function node, and then parse the data and do other stuff in the workflow. however until now, i’m stuck with the following error: ERROR: Always an Array of items has to be returned! and im not sure how to resolve it as im not a js developer.
any help is highly appreciated.