Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: ea0522 on May 30, 2024, 09:13:15 pm
-
Hai, I'm trying to import data in Enterprise Architect using a REST API call.
The REST API returns a nicely formatted JSON string.
In another javascript, I've managed to parse a valid JSON string.
However, when I try to use Fetch() to get the information from an URL, I get an error: "fetch is not defined".
Anyone has an example javascript I can adapt to test the fetch function?
Thanks.
-
You can simulate the fetch command with the following JavaScript example:
const http2 = new COMObject("MSXML2.ServerXMLHTTP");
http2.setTimeouts(15000, 15000, 15000, 900000);
http2.setProxy(2,"http://localhost:9000","");
http2.open("POST", url, false); // Use "true" for async
http2.setRequestHeader("Content-Type", "application/json");
http2.setRequestHeader("Authorization", "Bearer " + OPENAI_API_KEY);
http2.send(JSON.stringify(body));
if (http2.status == 200) {
Session.Output(http2.responseText);
} else {
Session.Output("Error: " + http2.status + " - " + http2.statusText);
}