Connect to postges database
# 🤝help
f
Hello, I'm am using Botpress Studio and want to connect to a postgres database with postgrest API. To test the interface I have written two scripts with axios GET and POST request to read and write data to the database which works well. But when I use the script in an botpress execute node, it doesn't work. I am not a programmer, but the following code works: (I have replaced the URL and the port): / Read from database machinenumbers using GET and axios package axios.get("http://111.111.111.11:2222/machinenumbers?number=eq.M01156") .then((response) => console.log(response.data)) .catch((error) => console.log(error)); // Insert data to database costumers using POST and axios package, json-format axios.post('http://111.111.111.11:2222/costumers', { "company": 'Flintstone GmbH', "firstname": "Fred", "name": 'Flintstone', "email": "fred@flintstone.com", "phone": "0049123456789" }) .then(function (response) { console.log("Write success"); }) .catch(function (error) { console.log(error); }); Can someone help me to realize the two functions in Botpress? Or is there an easier way?
b
Hello!, are you awaiting for those requests? using "await"?
Do you also have no authorization to send in the headers? do you have the database without any authorization?
Copy code
const jiraUrl = 'https://your-jira-url.com'
const jiraUsername = 'your-jira-username'
const jiraPassword = 'your-jira-password'
 
// get the current date and time in ISO format
const now = luxon.local().toISO()
 
// create the JQL query to get all issues that are not done
const jql = `status != Done AND updated >= "${now}" ORDER BY updated DESC`
 
// set the request headers for Jira API
const headers = {
  'Content-Type': 'application/json',
  Authorization: `Basic ${btoa(`${jiraUsername}:${jiraPassword}`)}`,
}
 
// make the request to Jira API to get all issues that are not done
const response = await axios.get(`${jiraUrl}/rest/api/2/search?jql=${jql}`, { headers })
 
// filter the response to only keep the issues that are not done
const issues = _.filter(response.data.issues, (issue) => issue.fields.status.name !== 'Done')
as in this example taken from the botpress documentation. 👆🏻
In Axios you pass the headers as an object after the url.
c
Hey I'm trying to make a chatbot that combines both stack ai and botpress. I did the workflow in botpress and from stack ai I made a bot using chatgpt which is connected to my database and I took the API of stack ai and connected it to botpress. And the API is not responding need help https://cdn.discordapp.com/attachments/1225403465895776307/1225456385043599471/EaseUS_2024_04__4_17_41_42.png?ex=66213232&is=660ebd32&hm=91bb3d374704240f8d12b124b4abf8d783212d656f602c5fddbcdddabeadb812&
c
I would recommend starting a new thread in #1111009377525186570
3 Views