Axios Network Error on API Call
# 🤝help
n
Every time I try to call the Chatbase API with Axios, I get an Axios Network Error: Error: Network Error (Status Code: undefined) Here is my code: const endpoint = 'https://www.chatbase.co/api/v1/chat'; const chatbot_id = 'SET'; const apiKey = 'SET'; const headers = { "Authorization":
Bearer ${apiKey}
, 'Content-Type': 'application/json' }; const data = { "messages": [ { "content": user.Conversation_Question, "role": "user" } ], "chatbotId": chatbot_id, "conversationid": "test-123456" }; try { const response = await axios.post(endpoint, data, { headers }); // If you need to extract the response JSON, you can use: // const responseData = response.data; // workflow.Chatbase_response = responseData['text']; } catch (error) { throw new Error(
stack-error: ${error}
); } Does anyone know how I can solve this error?
c
Are running this code from an "Execute Code"?
n
Yes!
Okay, maybe I found the problem. For some reason, Botpress keeps sending request to the URL without "www", while "www" is stated in the code:
This could explain the Network Error, because if I do this API call without 'www' it does not work (in Postman)
c
If it helps, try to use fetch instead of axios, maybe it works
n
If I use "fetch", it says it cannot find the name
c
Ah It's ok, sometimes, the intelessense of Botpress dont recognize
4 Views