not able to connect to mysql from botpress
# 🤝help
i
I have created a flask endpoint to connect to mysql database to insert some data. I am running this on ngrok and it is online In botpress in the execute code node, I am trying to call this API.
Copy code
async function submitDataToAPI() {
  const feedbackData = {
    // "user_name": workflow.username,
    // "user_phone": workflow.userPhone,
    "user_name": "ram",
    "user_phone": "91234567890",
    "start_time": workflow.usertimestart,
    "end_time": workflow.usertimeend,
    "messages": conversation.SummaryAgent.transcript,
    "feedbackgiven": workflow.FeedbackGiven
  }

    console.log(JSON.stringify(feedbackData))

    const options = {
    uri: 'http://3426-49-206-133-52.ngrok-free.app/api/submit_feedback',
    method: 'POST',
    headers:{
      'Content-Type': 'application/json',
      'Content-Length': '99999'
    },
    data: feedbackData
    //data: JSON.stringify(feedbackData)
  }

  try{
    console.log('before axios')
    await axios(options)
    console.log('after axios')
    console.log('Feedback submitted successfully')
  } catch(error){
    console.error('Error submitting Feedback: ', error)
  }
}

submitDataToAPI();
It works fine when I use it in Postman and records are created in db, but when I try the same in botpress, I get errors in logs. Is there anything wrong with how I call the API in botpress? https://cdn.discordapp.com/attachments/1233005134120747130/1233005134552891432/image.png?ex=6634bf84&is=66336e04&hm=2e010de982e7ff4d66fb0c36db5fbef91cc4555fea85251d444b68fb86dcabe6& https://cdn.discordapp.com/attachments/1233005134120747130/1233005134938898452/image.png?ex=6634bf84&is=66336e04&hm=44c15908f0dbd510e61d645213494f33e382d933564d0b3d253041edc4b7d34c& https://cdn.discordapp.com/attachments/1233005134120747130/1233005135332900896/image.png?ex=6634bf84&is=66336e04&hm=709e1333cc3a851a2cd4c67e71f96473115def5a62ace41343779756b4fed1a3&
f
ECONNREFUSED stands for “Connection Refused By Server.” That means the server you are trying to connect to has refused the connection request. Simply put, it means that your server is inaccessible. This error message is quite common and often shows up when using File Transfer Protocol (FTP) clients like FileZilla.
i
But the same is working when I hit the API via postman, it should work on botpress also right
f
It should. I have used Botpress with Ngrok before without any issues. Can you make sure that it's calling the same endpoint
f
Can you go through the body and the headers and make sure that it's not missing something
i
I have rechecked the headers and body, I am using the same headers in botpress as well. I am not able to understand why botpress is checking at port 80 when I have mentioned port 5000 (default port for flask) [b9506744ae] [bot-action] [flow:Conversation End] [node:Standard2] [card:Submit Feedback Data to Flask API]: Error submitting Feedback: {"message":"connect ECONNREFUSED 127.0.0.1:80","name":"Error","stack":"Error: connect ECONNREFUSED 127.0.0.1:80\n at zm.from (/var/task/customer_code.js:303:8883)\n at N.handleRequestError (/var/task/customer_code.js:306:9063)\n at N.emit (node:events:517:28)\n at m. (/var/task/customer_code.js:57:950)\n at ClientRequest.emit (node:events:517:28)\n at Socket.socketErrorListener (node:_http_client:501:9)\n at Socket.emit (node:events:517:28)\n at emitErrorNT (node:internal/streams/destroy:151:8)\n at emitErrorCloseNT (node:internal/streams/destroy:116:3)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"env":{},"headers":{"Accept":"*/*","Content-Type":"application/json","Content-Length":"99999","Accept-Encoding":"gzip, deflate, br","Connection":"keep-alive","User-Agent":"axios/1.4.0"},"withCredentials":false,"baseURL":"","uri":"http://localhost:5000/api/submit_feedback","method":"post","port":5000,"
f
Oh
Have you forwarded port 5000?
Also
Doesn't even matter
Your endpoint is wrong
Try and use Ngrok again, and make sure the ports match
Fyi you shouldn't send your forwarded address from Ngrok here 🙂
f
Looks like it might be trying port 80?
i
Yes, But I am not understanding why it is using port 80. Do you know how we can force it to use port 5000?
f
Maybe something is set up wrong
i
It is working now, I just made the change from axios(options) to axios.post()