This topic was automatically generated from Slack. You can find the original thread here.
Has anyone else had issues where MySQL is not being recognized by code when constructing a trigger via node.js?
When I run this:
if (!this.mysql.$auth) {
throw new Error("MySQL authentication details are not defined. Please check your MySQL app configuration.");
}
I get an error back that says: “MySQL authentication details are not defined. Please check your MySQL app configuration.”
Yet when I try to create a trigger based on MySQL in the workflow, it clearly shows that it’s connecting to the database fine.
Noting that I did include import mysql from ‘mysql2/promise’; at the top of the code, has anyone else run into the issue where code is not recognizing the MySQL configuration in Pipedream?
Thank you! I defined the Prop. For the following code:
import { axios } from "@pipedream/platform";
import mysql from 'mysql2/promise';
export default defineComponent({
props: {
fitbit: {
type: "app",
app: "fitbit",
},
mysql: {
type: "app",
app: "mysql",
},
},
async run({ steps, $ }) {
// Fetch activities from Fitbit API
const response = await axios($, {
url: `https://api.fitbit.com/1/user/-/activities/list.json?afterDate=2024-01-10&sort=asc&limit=100&offset=0`,
headers: {
Authorization: `Bearer ${this.fitbit.$auth.oauth_access_token}`,
},
});
const activities = response.activities;
// Check if MySQL auth details are defined
if (!this.mysql.$auth) {
console.log(this.mysql);
// throw new Error("MySQL authentication details are not defined. Please check your MySQL app configuration.");
}
I get the following response from the logs:
{ '$auth': undefined }
If the prop is in place, the connected app confirm to work in the context of a trigger, I am not sure what is preventing $auth from populating the information contained in the connected app
To use MySQL credentials directly in your Pipedream component without relying on this.mysql.$auth, you can define the credentials as properties within the props object of your component. Here’s an example of how you might modify the component to accept credentials as input: import mysql from 'mysql2/promise'; export default defineComponent({ props: { host: { type: "string", label: "Host", description: "The hostname or IP address of your MySQL server", }, port: { type: "integer", label: "Port", description: "The port your MySQL server is running on (typically 3306)", default: 3306, }, username: { type: "string", label: "Username", description: "The username to authenticate with your MySQL server", }, password: { type: "string", label: "Password", description: "The password to authenticate with your MySQL server", }, database: { type: "string", label: "Database", description: "The name of the database you wish to query", }, }, async run({ steps, $ }) { const { host, port, username, password, database } = this; const connection = await mysql.createConnection({ host, port, user: username, password, database, }); // Your query here const [rows] = await connection.execute('SELECT NOW()'); return rows; }, }); In this example, the MySQL credentials are defined as individual properties within the props object, allowing you to input them directly when you configure the step in the Pipedream UI. This method bypasses the use of this.mysql.$auth and allows you to use any MySQL credentials you provide.
@UMT4G7E5P@U02E9JYGE7L Sorry to drag you back in. While the update did allow me to access the MySQL Account selection interface as I mentioned above, it appears this.mysql.$auth is still not being populated. I tried the above suggestion from PI but was getting connection refused at the localhost IP when I tried to enter the creds manually. Any idea on how I can move forward? Open to workarounds if the bug can’t be prioritized.