I am trying to read an API using JavaScript. Since Snowflake Stored Procedures are JavaScript based, I tried the following Stored Procedure.
create or replace procedure myschema.stproc1()
returns string
language javascript
as
$$
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest();
// Open a new connection, using the GET request on the URL endpoint
request.open('GET', 'https://myappi.application.com/external/api/rest/v2/rooms/?includeCancelled=true&includePastReservations=true&limit=500', true);
request.onload = function () {
// Begin accessing JSON data here
}
// Send request
request.send();
$$
;
And, I am getting the below error when trying to call the Stored Procedure:
JavaScript execution error: Uncaught ReferenceError: XMLHttpRequest is not defined in STPROC1 at ' var request = new XMLHttpRequest();' position 22 stackstrace: STPROC1 line: 3
I am fairly new to both JavaScript and Procedures in Snowflake. So, couldn't figure out what the issue is. I am using this code based out of reference from here.