Just going around in circles trying to understand how to use the fetch JSON column to make a POST request to an API.
I struggle a lot with the syntax, and to be honest I don’t even know if it’s possible. But does anybody know what I need to do to get this test example from the API docs to work?
There’s HTTP module in Integromat. It can make POST requests. So you could first send a webhook from Glide to Integromat and then use HTTP module to make request to the API you want.
Just a couple of technical questions about JavaScript libraries that Glide uses in their plugins: Fetch JSON & JavaScript.
I know we cannot make POST requests by using the Fetch JSON column but our plan B can be a custom JS code and run it via JavaScript plugin. It’s is fine but sometimes I have problems to understand and find the correct syntax within all the JS libraries and flavors available around the world.
I read time ago that Glide uses Lodash as JS library and also, we can import other JS libraries but I have a doubt about the Fetch() function and the right/best syntax to use.
As you know, Fetch() API supports the Promise object and helps a lot to retrieve/handle data and intercept any error during the execution of the request.
For example, this simple code uses Promise objects:
but the above code cannot be used in Glide, the JS plugin doesn’t support it and we must change it using this syntax:
var Response = await fetch('https://yesno.wtf/api')
const Result= await Response.text();
return Result
Glide shows the result like (all is ok)
…
As you can imagine, if I try to run my Glide code in other JS editors, nothing works
So, my questions are:
Which JS library can I import into Glide in order to work/use Fetch API’s Promise objects?
If I want to use Bearer authorization in Glide’s JavaScript plugin, which JS library do I have to import/use?
If I want to test my Glide JS code on other online platforms like JSFiddle, what language do I have to choose to get right results?. I tested it using “TypeScript” but no luck!
@gvalero very good start, but it’s clear that you are just starting to learn JavaScript! Please do not mention me for help with code-I do not have time to help you with it. Good luck!
Thanks and sorry for tagging you. I just wanted to know a little more about a point you mentioned earlier.
The Fetch JSON column uses a GET request, and cannot use Bearer-style authorization.
but anyway, I still try to understand all JavaScript flavors when I need to create a bit more complex code and use the correct function.
Taking your example code, this won’t run in Glide JavaScript plugin (I think)
The plugin needs a fetch request with 2 “await” calls, something like this:
let response = await fetch(url, options); // resolves with response headers
let finalResult = await response.json(); // read body as json or text ( .text())
return finalResult
but, if the code does not use “await” calls (like your example), no result is shown in JS column:
fetch(url, options)
.then(response => response.json()) // read body as json or text ( .text())
.then(finalResult => console.log(finalResult));
this was my original intention of asking you.
Why the Glide JavaScript plugin is not able to work with API Fetch without using "await” calls?. Can I import another library to get it?
Sorry again for the inconvenience, felíz noche David!
All of that code can run inside Glide, if you understand what the await calls are doing and how JavaScript promises work. I’m sorry, I do not have time to help you with it.