Solar system from APsystems

Hi Rob, unfortunately not. There must be something going wrong with calculating the signature. I moved over to the app development environment, and there it worked, but of course it uses JavaScript. Crypto is not supported in Homey script, so this doesn’t work there.
I called out to Diederik (see reply from Patrick), because there’s already something that works.

// Requirements
const Homey = require(“homey”);
const crypto = require(“crypto”);
const { v4: uuidv4 } = require(“uuid”);
const fetch = require(“node-fetch”); // Voor Node.js, anders browser fetch

// Signature data
const api_key = Homey.env.CLIENT_ID;
const api_secret = Homey.env.CLIENT_SECRET;
const sid = Homey.env.CLIENT_SID;
const signature_method = “HmacSHA256”;
const nonce = uuidv4().replace(/-/g, “”);
const ts = Date.now();
const timestamp = ts.toString();

// Request data
const base_url = “https://api.apsystemsema.com:9282”;
const request_path = “/user/api/v2/systems/details/” + sid;
const http_method = “GET”;

// Create string to sign
var urlSegments = request_path.split(“/”);
var lastSegment = urlSegments[urlSegments.length - 1];
const stringToSign = ${timestamp}/${nonce}/${api_key}/${lastSegment}/${http_method}/${signature_method};

// Calculate signature
const hmacSha256 = crypto.createHmac(“sha256”, api_secret);
hmacSha256.update(stringToSign);
const signature = hmacSha256.digest(“base64”);

//Create headers
const header = {
“X-CA-AppId”: api_key,
“X-CA-Timestamp”: timestamp,
“X-CA-Nonce”: nonce,
“X-CA-Signature-Method”: “HmacSHA256”,
“X-CA-Signature”: signature,
};

// Create the full url
const url = base_url + request_path;
console.log(getpower);

// Make a GET request
fetch(url, { headers: header })
.then((response) => {
if (!response.ok) {
throw new Error(“Network response was not ok”);
}
return response.json();
})
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error(“Error:”, error);
});

class Driver extends Homey.Driver {
async onPair(session) {
const devices = “AP Systems”

}
}

module.exports = Driver;