Share feedback, ideas and get community help

Updated 2 months ago

fetch header

Hi...
I'm wondering if there is a way to fetch a remote API using script but passing "Header" parameters accoding to the suggested documentation:

https://docs.typebot.io/editor/blocks/logic/script ->

// βœ… This works
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1')
const data = JSON.parse(response)
...

I'm trying this approach but it fails at some point:
myHeaders.append("api_access_token", "ASDADSADADSASDASDASDASD"); let requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; let response = await fetch("https://url", requestOptions); let data = JSON.parse(response) return (data);

Any sugestion?
W
g
B
6 comments
On the same page see -
Limitations on scripts executed on server - https://docs.typebot.io/editor/blocks/logic/script#limitations-on-scripts-executed-on-server

there is an exact case about the issue you are facing i think
This is exactly what we saw, but it doesn't says anything about authentication headers on fetch and I'm wondering if it is possible...
That should work, what is the issue?
The problem is that when using the "functions" section in openAI assistants, the snippet code that you place, we require it to do a fetch sending several parameters that are not part of the URL (as it could be on a simple url GET), but sent through a Header such as authorization tokens and so on. .

When executing the function, openai indicates that it has no way to access it because something is going wrong.

If I emulate the output with a simple "return json" it does work!, which indicates that everything works fine with openAI and Typebot, but I can't make a fetch composed of headers and other parameters in code. Here an example:
Can you copy paste the code here so that I try?
Add a reply
Sign up and join the conversation on Discord