https://discord.gg/botpress logo
#🤝help
Axios Network Error on API Call
# 🤝help
n

nice-twilight-90450

01/11/2024, 12:15 PM
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

crooked-petabyte-82330

01/11/2024, 12:47 PM
Are running this code from an "Execute Code"?
n

nice-twilight-90450

01/11/2024, 12:57 PM
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

crooked-petabyte-82330

01/11/2024, 1:55 PM
If it helps, try to use fetch instead of axios, maybe it works
n

nice-twilight-90450

01/11/2024, 2:22 PM
If I use "fetch", it says it cannot find the name
c

crooked-petabyte-82330

01/11/2024, 8:05 PM
Ah It's ok, sometimes, the intelessense of Botpress dont recognize