Trying to get data from solis API

Wiil this be of any help:

1 Like

Hello everyone,
I have finally got the interface up and running. The last code Steve posted here had only one tiny error, a slash in line 43 in the function node. That had to be removed and then it worked.
Thanks to everyone who gave me help here! You guys are great!
Best regards

1 Like

can you share your final code?

This is my final code. Some data belonging to the system still needs to be updated.

[
    {
        "id": "9a840be7e82e3376",
        "type": "tab",
        "label": "Solis API",
        "disabled": false,
        "info": ""
    },
    {
        "id": "7a2fd68cb2eb35fd",
        "type": "function",
        "z": "9a840be7e82e3376",
        "name": "apply headers",
        "func": "// MD5 the payload\nconst payload = JSON.stringify(msg.payload)\nconst md5Hash = crypto.createHash('md5').update(payload, 'utf8').digest();\nconst contentMD5 = md5Hash.toString('base64')\n\n// extract other params or defaults\nmsg.method = msg.method || 'POST'\nconst canonicalResource = msg.canonicalResource || \"/v1/api/inverterDetail\"\nconst apiSecret = msg.secret || 'test-key'   // UPDATE ME\nconst domain = msg.domain || 'blahblah.com'  // UPDATE ME\nconst apiId = msg.apiId || 'your-api-id'  // UPDATE ME\nconst contentType = 'application/json' // fixed\n\n// this might need some work - just hoping the UTC format works\nconst date = new Date().toUTCString()\n\n// Generate the HMAC SHA-1 signature\nconst stringToSign = [\n    msg.method,  // HTTP verb\n    contentMD5,\n    contentType,\n    date,\n    canonicalResource\n].join('\\n')\n\nconst hmac = crypto.createHmac('sha1', apiSecret)\nhmac.update(stringToSign)\nconst signature = hmac.digest('base64')\n\n// add headers\n// doc states: \"all interface requests require adding\" \n// * Content MD5\n// * Content Type\n// * Date\n// * Authorization\nmsg.headers = msg.headers || {}\nmsg.headers['Content-MD5'] = contentMD5\nmsg.headers['Content-Type'] = contentType\nmsg.headers.Date = date\nmsg.headers.Authorization = `API ${apiId}:${signature}`\n\n// set full URL\nmsg.url = `https://${domain}${canonicalResource}`\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "crypto",
                "module": "crypto"
            }
        ],
        "x": 500,
        "y": 340,
        "wires": [
            [
                "ba2d79213a40cb8d",
                "3045441307964241"
            ]
        ]
    },
    {
        "id": "f05243cf398e86f6",
        "type": "inject",
        "z": "9a840be7e82e3376",
        "name": "UPDATE ME",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "method",
                "v": "POST",
                "vt": "str"
            },
            {
                "p": "canonicalResource",
                "v": "/v1/api/inverterDetail",
                "vt": "str"
            },
            {
                "p": "apiId",
                "v": "update me",
                "vt": "str"
            },
            {
                "p": "secret",
                "v": "update me",
                "vt": "str"
            },
            {
                "p": "domain",
                "v": "www.soliscloud.com:13333",
                "vt": "str"
            }
        ],
        "repeat": "30",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"id\": \"update me\", \"sn\": \"update me\"}",
        "payloadType": "json",
        "x": 180,
        "y": 340,
        "wires": [
            [
                "7a2fd68cb2eb35fd"
            ]
        ]
    },
    {
        "id": "ba2d79213a40cb8d",
        "type": "http request",
        "z": "9a840be7e82e3376",
        "name": "",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": true,
        "authType": "",
        "senderr": true,
        "headers": [],
        "x": 730,
        "y": 340,
        "wires": [
            [
                "b9092b8b5ffd31bf"
            ]
        ]
    },
    {
        "id": "3045441307964241",
        "type": "debug",
        "z": "9a840be7e82e3376",
        "name": "CHECK ME",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 240,
        "wires": []
    },
    {
        "id": "b9092b8b5ffd31bf",
        "type": "debug",
        "z": "9a840be7e82e3376",
        "name": "Result",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 970,
        "y": 280,
        "wires": []
    }
]

Apologies for the delay, did you get it all sorted?

yes, the code provided by @Asche does work ..thx a lot .. great work

1 Like

Thank you for getting in touch again. As xx_Nexus_xx had already written, access to the interface is working. The decisive factor for this was the support from Steve!