Can Anyone Help Me Fix Errors in Connecting Bubble to Pipedream for API Automation?

Cannot read properties of undefined (reading ‘pipe’)

, help me with the above error

Code:

import { axios } from “@pipedream/platform”;
import fs from “fs”;

export default defineComponent({
async run({ steps, $ }) {
let upload_url = steps.trigger.event.body.upload_url;
let file_url = steps.trigger.event.body.file_url;
console.log(file_url);

// Use axios to fetch the file as a stream
const response = await axios($, {
  method: 'get',
  url: file_url,
  responseType: 'stream',
});

// Temporary file path
const tempFilePath = `/tmp/file.wav`;
// Stream the response to a file
response.data.pipe(fs.createWriteStream(tempFilePath));

// Wait for the file to finish writing
await new Promise((resolve, reject) => {
  response.data.on('end', resolve);
  response.data.on('error', reject);
});

 // Configure the axios request
  let config = {
    method: 'put',
    maxBodyLength: Infinity,
    url: upload_url,
    headers: {
      'Content-Type': 'audio/wav',
      'x-api-key': 'FBPKkHG20U9aMif0DxrznaYYE3g7qpJy97ZPoaHB'
    },
    data: data
  };

await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
// Reference previous step data using the steps object and return data to use it in future steps
return steps.trigger.event
},
})

The error you’re encountering, “Cannot read properties of undefined (reading ‘pipe’)”, typically occurs when the object you’re trying to call .pipe() on is undefined. In your case, this seems to be happening with response.data. Given that you’re expecting response.data to be a stream (since you’ve set responseType: 'stream' in your axios request), the issue might be related to how the response is being handled or a misunderstanding of the axios response structure when using @pipedream/platform’s axios. First, ensure that the URL you’re fetching (file_url) is correct and that it indeed points to a file that can be streamed. If the URL is incorrect or the request to it fails for some reason, response.data might not be what you expect. However, based on the provided code and the @pipedream/platform axios behavior, remember that when you set responseType: 'stream', the expected usage might differ slightly from standard axios. In standard axios usage outside of Pipedream, response.data would be a stream. But within Pipedream, due to the custom axios wrapper, if you’re encountering issues, it might be worth verifying the behavior is as expected. Additionally, there’s a mistake in your code regarding the data variable in the PUT request configuration. It seems like data is not defined before its usage. If you’re trying to upload the file you’ve just written to /tmp/file.wav, you should read the file as a stream and assign it to data: ``` import { axios } from “@pipedream/platform”; import fs from “fs”; export default defineComponent({ async run({ steps, $ }) { let upload_url = steps.trigger.event.body.upload_url; let file_url = steps.trigger.event.body.file_url; console.log(file_url); // Use axios to fetch the file as a stream const response = await axios($, { method: ‘get’, url: file_url, responseType: ‘stream’, }); // Temporary file path const tempFilePath = /tmp/file.wav; // Stream the response to a file const writer = fs.createWriteStream(tempFilePath); response.data.pipe(writer); // Wait for the file to finish writing await new Promise((resolve, reject) => { writer.on('finish

Code:

// To use any npm package, just import it
import axios from “axios”

export default defineComponent({
async run({ steps, $ }) {

let upload_url = steps.trigger.event.body.upload_url;
let file = steps.trigger.event.body.file_url;
console.log(file);

  // Fetch the file as a blob
  let response = await fetch(file);
  let blob = await response.blob();
  console.log(blob);

  // Create FormData instance and append the file
  let data = new FormData();
  data.append('file', blob, 'file.wav'); // Ensure you provide a filename

  // Configure the axios request
  let config = {
    method: 'put',
    maxBodyLength: Infinity,
    url: upload_url,
    headers: {
      'Content-Type': 'audio/wav',
      'x-api-key': 'FBPKkHG20U9aMif0DxrznaYYE3g7qpJy97ZPoaHB'
    },
    data: data
  };

await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});

// Reference previous step data using the steps object and return data to use it in future steps
return steps.trigger.event

},
})

Error:
solve for this error

message: ‘Request failed with status code 403’,
name: ‘AxiosError’,
code: ‘ERR_BAD_REQUEST’,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false

It appears you’re encountering a 403 Forbidden error when attempting to upload a file using axios. This error typically indicates that the server understood the request but refuses to authorize it. This could be due to several reasons, such as incorrect API keys, lack of permissions, or other authorization issues. Here are a few steps you can take to troubleshoot and potentially solve this issue: 1. Verify API Key: Ensure that the x-api-key you’re using is correct and has the necessary permissions for the operation you’re trying to perform. 2. Check the URL: Make sure the upload_url you’re using is correct and that you have permission to upload files to it. 3. Content-Type Header: You’ve set the Content-Type to audio/wav. Confirm that this is the expected content type for the file you’re uploading and that the server supports it. 4. Cross-Origin Resource Sharing (CORS): If you’re making this request from a browser, ensure that the server supports CORS requests from your domain. 5. Server Logs: If you have access to the server, check the logs for more details on why the request is being forbidden. 6. Contact Support: If the server is not under your control, you might need to contact the server’s support team for more details on the error. Here’s a slightly modified version of your code with better error handling that might help you debug the issue: ``` import axios from “axios” export default defineComponent({ async run({ steps, $ }) { let upload_url = steps.trigger.event.body.upload_url; let file = steps.trigger.event.body.file_url; console.log(file); // Fetch the file as a blob let response = await fetch(file); let blob = await response.blob(); console.log(blob); // Create FormData instance and append the file let data = new FormData(); data.append(‘file’, blob, ‘file.wav’); // Ensure you provide a filename // Configure the axios request let config = { method: ‘put’, maxBodyLength: Infinity, url: upload_url, headers: { ‘Content-Type’: ‘audio/wav’, ‘x-api-key’: ‘FBPKkHG20U9aMif0DxrznaYYE3g7qpJy97ZPoaHB’ }, data: