Based on the code you’ve provided and the error message you’re encountering, it seems there might be an issue with how the MySQL authentication details are being accessed or configured within your Pipedream component code. Here’s a revised version of your code that should correctly use the MySQL $auth
object to connect to your database: ``` 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; // MySQL connection details const { host, port, username, password, database } = this.mysql.$auth; const connection = await mysql.createConnection({ host, port, user: username, password, database, }); // Iterate over the array of activities and insert into MySQL for (const activity of activities) { const query = INSERT INTO DashboardDB.fitbitactivitylog(logid, activeduration, activezoneminutestotal, activityname, activitytypeid, avgheartrate, calories, distance, distanceunit, duration, elevationGain, heartratelink, logtype, originalduration, originalstarttime, pace, speed, steps, tcxlink) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
; const values = [ activity.logid, activity.activeduration, activity.activezoneminutestotal, activity.activityname, activity.activitytypeid, activity.avgheartrate, activity.calories, activity.distance, activity.distanceunit, activity.duration, activity.elevationGain, activity.heartratelink, activity.logtype, activity.originalduration, activity.originalstarttime, activity.pace
I am getting the response
{ '$auth': undefined }
When I run 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.");
}
There is a MySQL database configured in connected accounts. When a trigger is tested against the database, the workflow successfully recognizes the connection to the database.
Why is Pipedream not defining $auth in the code above?
Based on the code snippet you provided, it seems that there might be an issue with how the MySQL $auth
object is being accessed or with the configuration of the MySQL app within Pipedream. To troubleshoot this, please ensure the following: 1. Confirm that the MySQL app is correctly configured in your Pipedream account’s connected apps section. 2. Make sure that the MySQL app has been authorized with the correct credentials (host, port, username, password, database). 3. Verify that there are no typos or errors in the property names within the $auth
object. If you’ve confirmed that the MySQL app is correctly configured and the issue persists, you may want to add additional logging to check the contents of this.mysql
before accessing $auth
. For example: ```
console.log(“MySQL prop:”, this.mysql);